struct

Proto::Wire::Writer

Inherits Struct < Value < Object

Writer wraps an IO and provides typed protobuf wire-format write primitives.

Typical message encode pattern: writer.write_tag(1, WireType::VARINT) writer.write_int32(value)

For embedded messages use write_embedded which buffers the sub-message, then writes the length prefix followed by the bytes.

Constants

DEFAULT_MAX_FIELD_LENGTH = (8 * 1024) * 1024

Constructors

new(io : IO, max_field_length : Int32 = DEFAULT_MAX_FIELD_LENGTH)
Source

Instance methods

write_bool(value : Bool) : Nil
Source
write_bool_field(field_number : Int32, value : Bool) : Nil

Write a bool field only if value is true.

Source
write_bytes(data : Bytes) : Nil
Source
write_bytes_field(field_number : Int32, value : Bytes) : Nil

Write a bytes field only if value is not empty.

Source
write_double(value : Float64) : Nil
Source
write_embedded(field_number : Int32, & : IO -> ) : Nil

Write a length-delimited field by buffering the block's output. Yields the underlying IO::Memory; the accumulated bytes are length-prefixed and written.

Source
write_fixed32(value : UInt32) : Nil
Source
write_fixed64(value : UInt64) : Nil
Source
write_float(value : Float32) : Nil
Source
write_int32(value : Int32) : Nil

int32: sign-extends to 64 bits (negative values become 10-byte varints)

Source
write_int32_field(field_number : Int32, value : Int32) : Nil

Write an int32 field only if value != 0.

Source
write_int64(value : Int64) : Nil
Source
write_packed(field_number : Int32, & : IO::Memory -> ) : Nil

Write a packed repeated field using the block to write each element into the buffer. Skips writing the field entirely if the array is empty.

Source
write_sfixed32(value : Int32) : Nil
Source
write_sfixed64(value : Int64) : Nil
Source
write_sint32(value : Int32) : Nil

sint32 / sint64 use zigzag encoding

Source
write_sint64(value : Int64) : Nil
Source
write_string(value : String) : Nil
Source
write_string_field(field_number : Int32, value : String) : Nil

Write a string field only if value is not empty.

Source
write_tag(field_number : Int32, wire_type : Int32) : Nil
Source
write_uint32(value : UInt32) : Nil
Source
write_uint64(value : UInt64) : Nil
Source
write_uint64_field(field_number : Int32, value : UInt64) : Nil

Write a uint64 field only if value != 0.

Source
write_varint(value : UInt64) : Nil
Source