25#ifndef A11_NET_BYTE_CHUNKING_H_
26#define A11_NET_BYTE_CHUNKING_H_
35#include <absl/base/nullability.h>
36#include <absl/status/status.h>
37#include <absl/status/statusor.h>
57 template <
typename Sink>
59 sink.Append(
"BytePacket{type=");
65 sink.Append(
", sequence=");
67 sink.Append(
", packet_count=");
69 sink.Append(
", payload_size=");
70 sink.Append(packet.
payload.size());
89 std::string_view bytes, std::uint64_t transient_id,
size_t packet_size);
97 std::string bytes, std::uint64_t transient_id,
size_t packet_size);
125 absl::StatusOr<std::optional<std::string>>
Feed(std::string packet);
136 static constexpr size_t kImplSize = 256;
137 static constexpr size_t kImplAlignment =
alignof(std::max_align_t);
139 Impl* absl_nonnull GetImpl();
140 [[nodiscard]]
const Impl* absl_nonnull GetImpl()
const;
142 alignas(kImplAlignment) std::byte impl_[kImplSize];
Bounded, thread-safe reassembly for interleaved binary messages.
Definition byte_chunking.h:115
size_t pending_message_count() const
Number of message ids currently awaiting more packets.
Definition byte_chunking.cc:385
ByteReassembler(const ByteReassembler &)=delete
ByteReassembler & operator=(const ByteReassembler &)=delete
absl::StatusOr< std::optional< std::string > > Feed(std::string packet)
Admit one packet and return a complete message when this finishes one.
Definition byte_chunking.cc:274
size_t pending_byte_count() const
Aggregate payload bytes retained by incomplete messages.
Definition byte_chunking.cc:391
~ByteReassembler()
Definition byte_chunking.cc:262
void Clear()
Discard every incomplete message, for example when a channel aborts.
Definition byte_chunking.cc:378
absl::StatusOr< BytePacket > ParseOwnedBytePacket(std::string packet)
Parse one packet, reusing its buffer as the payload.
Definition byte_chunking.cc:232
absl::StatusOr< std::vector< std::string > > SplitOwnedBytesIntoPackets(std::string bytes, std::uint64_t transient_id, size_t packet_size)
Split bytes the caller owns, reusing the buffer when it fits a packet.
Definition byte_chunking.cc:207
absl::StatusOr< BytePacket > ParseBytePacket(std::string_view packet)
Parse and validate one packet without retaining the input view.
Definition byte_chunking.cc:224
BytePacketType
Packet shapes in the A11 byte-chunking wire format.
Definition byte_chunking.h:42
@ kLengthSuffixedByteChunk
absl::StatusOr< std::vector< std::string > > SplitBytesIntoPackets(std::string_view bytes, std::uint64_t transient_id, size_t packet_size)
Split bytes into A11 packets with fixed little-endian suffixes.
Definition byte_chunking.cc:115
Bounds packet size and incomplete-message memory during reassembly.
Definition byte_chunking.h:76
size_t packet_size
Maximum encoded packet size.
Definition byte_chunking.h:77
size_t max_pending_messages
Simultaneous incomplete messages.
Definition byte_chunking.h:79
size_t max_message_size
Reassembled message limit.
Definition byte_chunking.h:78
size_t max_pending_bytes
Aggregate pending payload limit.
Definition byte_chunking.h:80
absl::Status Validate() const
Validate that all limits can represent at least one useful packet.
Definition byte_chunking.cc:98
Parsed packet metadata plus the owned piece of application payload.
Definition byte_chunking.h:49
std::uint32_t sequence
Zero-based position in the message.
Definition byte_chunking.h:53
BytePacketType type
Packet shape.
Definition byte_chunking.h:50
std::uint32_t packet_count
Total count, when supplied by the first packet.
Definition byte_chunking.h:54
std::string payload
Bytes contributed by this packet.
Definition byte_chunking.h:51
std::uint64_t transient_id
Definition byte_chunking.h:52
friend void AbslStringify(Sink &sink, const BytePacket &packet)
Definition byte_chunking.h:58
Definition byte_chunking.cc:241