Filo.Protobuf.Wire (Filo v0.2.0)

Copy Markdown View Source

Protobuf wire-format primitives (proto3): varints, zigzag, fixed64, tags, and length-delimited fields — just enough of the encoding to (de)serialize the Hrana 3 messages. The message-level codecs live in Filo.Protobuf.

Encoders return iodata/0 (callers wrap a whole message in IO.iodata_to_binary/1). decode_fields/1 returns the fields in wire order as {field_number, value} where value is one of {:varint, n}, {:fixed64, <<8 bytes>>}, {:len, binary}, or {:fixed32, <<4 bytes>>}; repeated fields appear once per occurrence.

Summary

Functions

Decodes a fixed64 double payload.

Splits a message into its {field_number, value} fields, in wire order.

Length-prefixes a message (no tag) for the cursor response stream.

A varint field for a bool.

A fixed64 field for a double (little-endian IEEE-754).

A varint field for a possibly-negative int32/int64 (sign-extended to 64 bits).

A length-delimited field (string, bytes, or a sub-message).

A zigzag varint field for a sint64.

A varint field for a non-negative integer (uint32/uint64/enum).

Splits a length-delimited stream (the inverse of repeated delimit/1) into messages.

Encodes a field tag (field_number << 3 | wire_type).

Encodes an unsigned integer as a base-128 varint.

Encodes a signed integer with zigzag (so small magnitudes stay small).

Functions

decode_double(arg)

@spec decode_double(binary()) :: float()

Decodes a fixed64 double payload.

decode_fields(bin)

@spec decode_fields(binary()) :: [{pos_integer(), term()}]

Splits a message into its {field_number, value} fields, in wire order.

delimit(data)

@spec delimit(iodata()) :: iodata()

Length-prefixes a message (no tag) for the cursor response stream.

field_bool(field, bool)

@spec field_bool(pos_integer(), boolean()) :: iodata()

A varint field for a bool.

field_double(field, f)

@spec field_double(pos_integer(), float()) :: iodata()

A fixed64 field for a double (little-endian IEEE-754).

field_int(field, n)

@spec field_int(pos_integer(), integer()) :: iodata()

A varint field for a possibly-negative int32/int64 (sign-extended to 64 bits).

field_len(field, data)

@spec field_len(pos_integer(), iodata()) :: iodata()

A length-delimited field (string, bytes, or a sub-message).

field_sint64(field, n)

@spec field_sint64(pos_integer(), integer()) :: iodata()

A zigzag varint field for a sint64.

field_varint(field, n)

@spec field_varint(pos_integer(), non_neg_integer()) :: iodata()

A varint field for a non-negative integer (uint32/uint64/enum).

split_delimited(bin)

@spec split_delimited(binary()) :: [binary()]

Splits a length-delimited stream (the inverse of repeated delimit/1) into messages.

tag(field, wire_type)

@spec tag(pos_integer(), 0..5) :: iodata()

Encodes a field tag (field_number << 3 | wire_type).

varint(n)

@spec varint(non_neg_integer()) :: iodata()

Encodes an unsigned integer as a base-128 varint.

zigzag_decode(z)

@spec zigzag_decode(non_neg_integer()) :: integer()

Inverse of zigzag_encode/1.

zigzag_encode(n)

@spec zigzag_encode(integer()) :: non_neg_integer()

Encodes a signed integer with zigzag (so small magnitudes stay small).