Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/source/extensions/filters/network/zookeeper_proxy/utils.h
Line
Count
Source
1
#pragma once
2
3
#include <cstdint>
4
#include <string>
5
6
#include "envoy/common/platform.h"
7
8
#include "source/common/buffer/buffer_impl.h"
9
#include "source/common/common/byte_order.h"
10
#include "source/common/common/logger.h"
11
12
namespace Envoy {
13
namespace Extensions {
14
namespace NetworkFilters {
15
namespace ZooKeeperProxy {
16
17
/**
18
 * Helper for extracting ZooKeeper data from a buffer.
19
 *
20
 * If at any point a peek is tried beyond max_len, an EnvoyException
21
 * will be thrown. This is important to protect Envoy against malformed
22
 * requests (e.g.: when the declared and actual length don't match).
23
 *
24
 * Note: ZooKeeper's protocol uses network byte ordering (big-endian).
25
 */
26
class BufferHelper : public Logger::Loggable<Logger::Id::filter> {
27
public:
28
624
  BufferHelper(uint32_t max_len) : max_len_(max_len) {}
29
30
  int32_t peekInt32(Buffer::Instance& buffer, uint64_t& offset);
31
  int64_t peekInt64(Buffer::Instance& buffer, uint64_t& offset);
32
  std::string peekString(Buffer::Instance& buffer, uint64_t& offset);
33
  bool peekBool(Buffer::Instance& buffer, uint64_t& offset);
34
  void skip(uint32_t len, uint64_t& offset);
35
4.89k
  void reset() { current_ = 0; }
36
37
private:
38
  void ensureMaxLen(uint32_t size);
39
40
  const uint32_t max_len_;
41
  uint32_t current_{};
42
};
43
44
} // namespace ZooKeeperProxy
45
} // namespace NetworkFilters
46
} // namespace Extensions
47
} // namespace Envoy