Minimal protobuf (proto2) wire-format codec, just enough for the Riak PBC
messages FakeRiak.RiakPBC speaks.
Only the wire types Riak's KV messages use are decoded: varint (0) and length-delimited (2). Unknown fixed64 (1) and fixed32 (5) fields are skipped; the long-deprecated group types (3/4) are treated as malformed. Field types are not schema-checked — a decoded message is just a map of field number to the values seen, in order, and the caller picks out the fields it knows.
Summary
Types
A decoded field value: a varint as an integer, or raw bytes.
Field number => values in order of appearance.
Functions
Decode a message payload into its fields.
Encode fields, in the given order, into a message payload. Integers and
booleans go as {:varint, n}; bytes, strings and embedded messages as
{:bytes, iodata}.
The value of a field, with proto2 scalar semantics: when a scalar field appears more than once, the last occurrence wins.
Types
@type field_value() :: non_neg_integer() | binary()
A decoded field value: a varint as an integer, or raw bytes.
@type fields() :: %{optional(pos_integer()) => [field_value()]}
Field number => values in order of appearance.
Functions
Decode a message payload into its fields.
Returns :error on malformed input: a truncated field, an over-long varint,
a group wire type, or field number 0.
@spec encode([{pos_integer(), {:varint, non_neg_integer()} | {:bytes, iodata()}}]) :: iodata()
Encode fields, in the given order, into a message payload. Integers and
booleans go as {:varint, n}; bytes, strings and embedded messages as
{:bytes, iodata}.
@spec last(fields(), pos_integer(), field_value() | nil) :: field_value() | nil
The value of a field, with proto2 scalar semantics: when a scalar field appears more than once, the last occurrence wins.