Byte buffer / view aliases and protobuf base-128 varint codec.
Non-owning view over a contiguous run of bytes (a C++17 stand-in for std::span<const std::uint8_t>).
Definition bytes.hpp:17
Stateful codec sitting between the transport and the connection.
Definition frame_helper.hpp:30
FrameHelper(const FrameHelper &)=delete
FrameHelper & operator=(FrameHelper &&)=delete
FrameHelper(FrameHelper &&)=delete
FrameHelper & operator=(const FrameHelper &)=delete
virtual void encode(std::uint32_t msg_type, ByteView payload, ByteBuffer &out)=0
Serialize a message (numeric type id + protobuf payload) to wire bytes, appending them to out.
virtual ByteBuffer connect_bytes()
Bytes to transmit immediately after the TCP connection is established (the client's first handshake f...
Definition frame_helper.hpp:69
std::function< void()> HandshakeReady
Definition frame_helper.hpp:58
virtual FrameStatus next(std::uint32_t &out_type, ByteView &out_payload)=0
Try to extract the next complete frame.
virtual bool needs_handshake() const
True if the transport requires a handshake before application messages (and before the connection sho...
Definition frame_helper.hpp:63
virtual ~FrameHelper()=default
std::function< void(const std::string &what)> HandshakeError
Definition frame_helper.hpp:59
virtual void set_handshake_handlers(HandshakeReady, HandshakeError)
Register callbacks fired when the handshake completes or fails.
Definition frame_helper.hpp:78
virtual void feed(ByteView data)=0
Append freshly received bytes to the internal reassembly buffer.
FrameStatus
Result of attempting to pull a frame from the reassembly buffer.
Definition frame_helper.hpp:17
@ NeedMore
The buffer holds only a partial frame; feed more bytes.
@ Ok
A complete value was decoded.
std::vector< std::uint8_t > ByteBuffer
Owning, growable byte buffer.
Definition bytes.hpp:13
constexpr std::size_t max_frame_payload
Hard upper bound on a single frame's payload, guarding against a hostile or corrupt length prefix (16...
Definition frame_helper.hpp:83