thrifty/field
Values
pub fn encode_field_header(
field_id: Int,
field_type: types.FieldType,
last_field_id: Int,
) -> BitArray
Encode a field header into a BitArray using compact delta encoding.
Inputs
field_id: absolute field identifier.field_type: thetypes.FieldTypedescribing the field payload.last_field_id: previous field id for delta calculation.
Outputs
- Returns a
BitArraycontaining either a single header byte (short form) or a header byte followed by a varint-encoded absolute field id (long form).
Semantics
- Short form is used when
1 <= delta <= 15wheredelta = field_id - last_field_id. - Boolean fields use inline header encodings and follow the same delta rules.
pub fn read_field_header(
reader: types.Reader,
last_field_id: Int,
) -> Result(#(types.FieldHeader, types.Reader), types.DecodeError)
Read a field header from the reader and advance the reader.
Inputs
reader: atypes.Readerpositioned at the start of a field header.last_field_id: the previous field id used to decode delta-encoded ids.
Outputs
Ok(#(types.FieldHeader, types.Reader))on success where the returnedtypes.Readeris advanced past the header.Error(types.DecodeError)for truncated input or invalid header bytes.
Semantics
- Supports the compact protocol short and long forms: short form encodes small deltas in the header byte; long form encodes an absolute field id as a following varint.