Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/source/extensions/filters/network/thrift_proxy/header_transport_impl.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
3
#include <string>
4
5
#include "envoy/buffer/buffer.h"
6
7
#include "source/extensions/filters/network/thrift_proxy/app_exception_impl.h"
8
#include "source/extensions/filters/network/thrift_proxy/metadata.h"
9
#include "source/extensions/filters/network/thrift_proxy/thrift.h"
10
#include "source/extensions/filters/network/thrift_proxy/transport.h"
11
12
#include "absl/types/optional.h"
13
14
namespace Envoy {
15
namespace Extensions {
16
namespace NetworkFilters {
17
namespace ThriftProxy {
18
19
/**
20
 * HeaderTransportImpl implements the Thrift Header transport.
21
 * See https://github.com/apache/thrift/blob/master/doc/specs/HeaderFormat.md and
22
 * https://github.com/apache/thrift/blob/master/lib/cpp/src/thrift/transport/THeaderTransport.h
23
 * (for constants not specified in the spec).
24
 */
25
class HeaderTransportImpl : public Transport {
26
public:
27
  // Transport
28
0
  const std::string& name() const override { return TransportNames::get().HEADER; }
29
0
  TransportType type() const override { return TransportType::Header; }
30
  bool decodeFrameStart(Buffer::Instance& buffer, MessageMetadata& metadata) override;
31
  bool decodeFrameEnd(Buffer::Instance& buffer) override;
32
  void encodeFrame(Buffer::Instance& buffer, const MessageMetadata& metadata,
33
                   Buffer::Instance& message) override;
34
35
0
  static bool isMagic(uint16_t word) { return word == Magic; }
36
37
  static constexpr int32_t MaxFrameSize = 0x3FFFFFFF;
38
39
private:
40
  static constexpr uint16_t Magic = 0x0FFF;
41
42
  static int16_t drainVarIntI16(Buffer::Instance& buffer, int32_t& header_size, const char* desc);
43
  static int32_t drainVarIntI32(Buffer::Instance& buffer, int32_t& header_size, const char* desc);
44
  static std::string drainVarString(Buffer::Instance& buffer, int32_t& header_size,
45
                                    const char* desc);
46
  static void writeVarString(Buffer::Instance& buffer, const absl::string_view str);
47
48
  absl::optional<AppExceptionType> exception_;
49
  std::string exception_reason_;
50
};
51
52
} // namespace ThriftProxy
53
} // namespace NetworkFilters
54
} // namespace Extensions
55
} // namespace Envoy