protobin
Types
pub type DecodeResult(t) =
Result(t, ParseError)
pub type ParseError {
UnknownWireType(Int, pos: Int)
InvalidVarInt(leftover_bits: BitArray, acc: BitArray, pos: Int)
InvalidFixed(size: Int, bits: BitArray, pos: Int)
InvalidLen(len: Int, value_bits: BitArray, pos: Int)
UnableToDecode(List(decode.DecodeError))
}
Constructors
-
UnknownWireType(Int, pos: Int) -
InvalidVarInt(leftover_bits: BitArray, acc: BitArray, pos: Int) -
InvalidFixed(size: Int, bits: BitArray, pos: Int) -
InvalidLen(len: Int, value_bits: BitArray, pos: Int) -
UnableToDecode(List(decode.DecodeError))
pub type Parsed(t) {
Parsed(value: t, rest: BitArray, pos: Int)
}
Constructors
-
Parsed(value: t, rest: BitArray, pos: Int)
pub type ValueParser =
fn(BitArray, Int) -> Result(Parsed(BitArray), ParseError)
pub type ValueResult =
Result(Parsed(BitArray), ParseError)
Values
pub fn decode_bool() -> decode.Decoder(Bool)
pub fn decode_fixed(size: Int) -> decode.Decoder(Int)
pub fn decode_multiple(
of decoder: decode.Decoder(t),
using parser: fn(BitArray, Int) -> Result(
Parsed(BitArray),
ParseError,
),
) -> decode.Decoder(List(t))
Decode a repeated field that may be either packed or expanded.
If it is impossible for a field to be packed (ie because it is encoded as
a LEN) and therefore there is no ValueParser for it, then use the
stdlib’s decode.list() instead.
pub fn decode_protobuf(
using decoder: fn() -> decode.Decoder(t),
named name: String,
default default: t,
) -> decode.Decoder(t)
pub fn decode_string() -> decode.Decoder(String)
pub fn decode_uint() -> decode.Decoder(Int)
pub fn parse(
from bits: BitArray,
using decoder: decode.Decoder(t),
) -> Result(Parsed(t), ParseError)
pub fn parse_varint(
bits: BitArray,
pos: Int,
) -> Result(Parsed(BitArray), ParseError)
Reads the bits from a varint and parses them a BitArray. The returned bits
can be parsed as a uint.
For a decoder that does this, use decoders.uint().
The continuation bits are not included, so the value’s bit size will be a multiple of 7.
pub fn read_fixed(
size: Int,
) -> fn(BitArray, Int) -> Result(Parsed(BitArray), ParseError)
Size is in bits, usually either 32 or 64.
Size must be a multiple of 8, or the returned position will be incorrect.
pub fn read_varint(
bits: BitArray,
pos: Int,
) -> Result(Parsed(BitArray), ParseError)
Reads the bits from a varint and returns all of them. They cannot be parsed as a uint.
Specifically, the continuation bits are included, so the value’s bit size will be a multiple of 8.