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>
43 sizeof(std::uint64_t) + 2 *
sizeof(std::uint32_t) + 2;
61 template <
typename Sink>
63 sink.Append(
"BytePacket{type=");
69 sink.Append(
", sequence=");
71 sink.Append(
", packet_count=");
73 sink.Append(
", payload_size=");
74 sink.Append(packet.
payload.size());
93 std::string_view bytes, std::uint64_t transient_id,
size_t packet_size);
101 std::string bytes, std::uint64_t transient_id,
size_t packet_size);
129 absl::StatusOr<std::optional<std::string>>
Feed(std::string packet);
140 static constexpr size_t kImplSize = 256;
141 static constexpr size_t kImplAlignment =
alignof(std::max_align_t);
143 Impl* absl_nonnull GetImpl();
144 [[nodiscard]]
const Impl* absl_nonnull GetImpl()
const;
146 alignas(kImplAlignment) std::byte impl_[kImplSize];
Bounded, thread-safe reassembly for interleaved binary messages.
Definition byte_chunking.h:119
size_t pending_message_count() const
Number of message ids currently awaiting more packets.
Definition byte_chunking.cc:384
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:273
size_t pending_byte_count() const
Aggregate payload bytes retained by incomplete messages.
Definition byte_chunking.cc:390
~ByteReassembler()
Definition byte_chunking.cc:261
void Clear()
Discard every incomplete message, for example when a channel aborts.
Definition byte_chunking.cc:377
absl::StatusOr< BytePacket > ParseOwnedBytePacket(std::string packet)
Parse one packet, reusing its buffer as the payload.
Definition byte_chunking.cc:231
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:206
absl::StatusOr< BytePacket > ParseBytePacket(std::string_view packet)
Parse and validate one packet without retaining the input view.
Definition byte_chunking.cc:223
BytePacketType
Packet shapes in the A11 byte-chunking wire format.
Definition byte_chunking.h:46
@ kLengthSuffixedByteChunk
constexpr size_t kMinimumBytePacketSize
Smallest packet that holds framing metadata and one payload byte.
Definition byte_chunking.h:42
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:114
stores::ChunkStoreReaderOptions options
Definition runtime_streams.cc:31
Bounds packet size and incomplete-message memory during reassembly.
Definition byte_chunking.h:80
size_t packet_size
Maximum encoded packet size.
Definition byte_chunking.h:81
size_t max_pending_messages
Simultaneous incomplete messages.
Definition byte_chunking.h:83
size_t max_message_size
Reassembled message limit.
Definition byte_chunking.h:82
size_t max_pending_bytes
Aggregate pending payload limit.
Definition byte_chunking.h:84
absl::Status Validate() const
Validate that all limits can represent at least one useful packet.
Definition byte_chunking.cc:97
Parsed packet metadata plus the owned piece of application payload.
Definition byte_chunking.h:53
std::uint32_t sequence
Zero-based position in the message.
Definition byte_chunking.h:57
BytePacketType type
Packet shape.
Definition byte_chunking.h:54
std::uint32_t packet_count
Total count, when supplied by the first packet.
Definition byte_chunking.h:58
std::string payload
Bytes contributed by this packet.
Definition byte_chunking.h:55
std::uint64_t transient_id
Definition byte_chunking.h:56
friend void AbslStringify(Sink &sink, const BytePacket &packet)
Definition byte_chunking.h:62
Definition byte_chunking.cc:240