11#ifndef A11_NET_BYTE_CHUNKING_H_
12#define A11_NET_BYTE_CHUNKING_H_
21#include <absl/base/nullability.h>
22#include <absl/status/status.h>
23#include <absl/status/statusor.h>
43 template <
typename Sink>
45 sink.Append(
"BytePacket{type=");
51 sink.Append(
", sequence=");
53 sink.Append(
", packet_count=");
55 sink.Append(
", payload_size=");
75 std::string_view bytes, std::uint64_t transient_id,
size_t packet_size);
97 absl::StatusOr<std::optional<std::string>>
Feed(std::string
packet);
108 static constexpr size_t kImplSize = 256;
109 static constexpr size_t kImplAlignment =
alignof(std::max_align_t);
114 alignas(kImplAlignment) std::byte impl_[kImplSize];
Bounded, thread-safe reassembly for interleaved binary messages.
Definition byte_chunking.h:87
size_t pending_message_count() const
Number of message ids currently awaiting more packets.
Definition byte_chunking.cc:334
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:224
size_t pending_byte_count() const
Aggregate payload bytes retained by incomplete messages.
Definition byte_chunking.cc:340
~ByteReassembler()
Definition byte_chunking.cc:212
void Clear()
Discard every incomplete message, for example when a channel aborts.
Definition byte_chunking.cc:327
absl::StatusOr< BytePacket > ParseBytePacket(std::string_view packet)
Parse and validate one packet without retaining the input view.
Definition byte_chunking.cc:142
BytePacketType
Packet shapes in the Action Engine byte-chunking wire format.
Definition byte_chunking.h:28
@ kLengthSuffixedByteChunk
absl::StatusOr< std::vector< std::string > > SplitBytesIntoPackets(std::string_view bytes, std::uint64_t transient_id, size_t packet_size)
Split bytes into Action Engine packets with fixed little-endian suffixes.
Definition byte_chunking.cc:103
Future< T > SubmitWithCancellationHook(absl::AnyInvocable< absl::StatusOr< T >() && > work, std::function< void()> cancellation_hook, thread::TreeOptions tree_options)
Run work on A11's fiber pool with application-specific cancellation.
Definition executor.h:30
Bounds packet size and incomplete-message memory during reassembly.
Definition byte_chunking.h:62
size_t packet_size
Maximum encoded packet size.
Definition byte_chunking.h:63
size_t max_pending_messages
Simultaneous incomplete messages.
Definition byte_chunking.h:65
size_t max_message_size
Reassembled message limit.
Definition byte_chunking.h:64
size_t max_pending_bytes
Aggregate pending payload limit.
Definition byte_chunking.h:66
absl::Status Validate() const
Validate that all limits can represent at least one useful packet.
Definition byte_chunking.cc:86
Parsed packet metadata plus the owned piece of application payload.
Definition byte_chunking.h:35
std::uint32_t sequence
Zero-based position in the message.
Definition byte_chunking.h:39
BytePacketType type
Packet shape.
Definition byte_chunking.h:36
std::uint32_t packet_count
Total count, when supplied by the first packet.
Definition byte_chunking.h:40
std::string payload
Bytes contributed by this packet.
Definition byte_chunking.h:37
std::uint64_t transient_id
Id used to interleave messages safely.
Definition byte_chunking.h:38
friend void AbslStringify(Sink &sink, const BytePacket &packet)
Definition byte_chunking.h:44
Definition byte_chunking.cc:190