ProtoWriter
struct ProtoWriterAccumulates proto3-encoded fields into an owned byte buffer.
Example:
var w = ProtoWriter()
w.write_string(1, "hello") # field 1: string
w.write_int64(2, 42) # field 2: int64
w.write_bool(3, True) # field 3: bool
var payload = w.take() # List[UInt8] ready for LPM framing
Implements Copyable, Movable
- Fields
buf: List[UInt8]
__init__
def __init__(out self) __len__
def __len__(self) -> Int take
def take(mut self) -> List[UInt8] Move the accumulated bytes out, leaving the writer empty.
bytes
def bytes(self) -> List[UInt8] Copy the accumulated bytes (writer stays usable).
write_uint64
def write_uint64(mut self, field: Int, value: UInt64) write_int64
def write_int64(mut self, field: Int, value: Int64) write_sint64
def write_sint64(mut self, field: Int, value: Int64) write_bool
def write_bool(mut self, field: Int, value: Bool) write_enum
def write_enum(mut self, field: Int, value: Int) write_fixed64
def write_fixed64(mut self, field: Int, value: UInt64) write_fixed32
def write_fixed32(mut self, field: Int, value: UInt32) write_double
def write_double(mut self, field: Int, value: Float64) write_float
def write_float(mut self, field: Int, value: Float32) write_bytes
def write_bytes(mut self, field: Int, value: Span[UInt8]) A length-delimited field: the tag, the length, then the bytes.
The bytes are copied in one go. A byte at a time is invisible on a
string field and is the whole cost of a large one — Arrow Flight puts
a record batch in data_body, so this copy is as big as the data the
server is sending.
write_string
def write_string(mut self, field: Int, value: String) write_message
def write_message(mut self, field: Int, sub: Span[UInt8]) Embed a pre-encoded sub-message (its own proto3 bytes).