gizlang:protobuf
the Protocol Buffers wire format. A message is a list of fields; a field has a number, a wire type and its value: a varint, a fixed 32 or 64 bit word (both in value), or length-delimited bytes (a string, bytes, a nested message or a packed list, in data). The schema is the caller's: it reads the numbers it knows and skips the rest, as the format asks.
import * as Protobuf from "gizlang:protobuf";Types
Field
type Field = { number: i64; wire: i64; value: i64; data: bytes; }One field of a message.
number:i64wire:i64value:i64data:bytes
Wire
type Wire = { data: bytes; at: i64; end: i64; }A message read in place: its bytes and the range [at, end) still to read. Nothing is copied until a caller slices.
data:bytesat:i64end:i64
Span
type Span = { number: i64; wire: i64; value: u64; start: i64; end: i64; }A field read in place: its number, its wire type, the bits of a varint or a fixed word, and the range [start, end) of its bytes (of length-delimited bytes, their content).
number:i64wire:i64value:u64start:i64end:i64
Functions
varintField
function varintField(number: i64, value: i64): FieldA varint field (int32, int64, uint32, uint64, bool, enum); use zigzag for sint32 and sint64.
bytesField
function bytesField(number: i64, data: bytes): FieldA bytes field.
stringField
function stringField(number: i64, text: string): FieldA string field.
messageField
function messageField(number: i64, fields: Vec<Field>): FieldA nested message field.
Effects: fail.
fixed32Field
function fixed32Field(number: i64, value: i64): FieldA fixed32 field (fixed32, sfixed32, float bits).
fixed64Field
function fixed64Field(number: i64, value: i64): FieldA fixed64 field (fixed64, sfixed64, double bits).
packedField
function packedField(number: i64, values: Vec<i64>): FieldA packed list of varints in one field.
Effects: fail.
zigzag
function zigzag(value: i64): i64The sint32 or sint64 encoding of a signed value.
Effects: fail.
unzigzag
function unzigzag(value: i64): i64The signed value of a zigzag encoding.
Effects: fail.
encode
function encode(fields: Vec<Field>): bytesThe wire form of a message.
Effects: fail.
reader
function reader(data: bytes): WireA reader of all of data.
decode
function decode(data: bytes): Vec<Field> throws stringThe fields of a message, in order; an error for a field that is cut, a number of 0 or a group (wire type 3 or 4).
Effects: fail.
last
function last(fields: Vec<Field>, number: i64): Option<Field>The last field with number: a repeated scalar keeps its last value.
Effects: fail.
all
function all(fields: Vec<Field>, number: i64): Vec<Field>Every field with number, in order (a repeated field).
Effects: fail.
unpacked
function unpacked(field: Field): Vec<i64> throws stringThe varints of a packed field (or of one field that was not packed).
Effects: fail.
Methods
Wire.varint
function Wire.varint(self: mut Wire): u64 throws stringThe next varint.
Effects: fail.
Wire.take
function Wire.take(self: mut Wire, n: i64): Wire throws stringThe next n bytes, as a reader of their own.
Effects: fail.
Wire.block
function Wire.block(self: mut Wire): Wire throws stringThe next length-delimited bytes, as a reader of their own.
Effects: fail.
Wire.next
function Wire.next(self: mut Wire): Span throws stringThe next field.
Effects: fail.
Wire.skip
function Wire.skip(self: mut Wire, wire: i64): bool throws stringPasses the value of a field of wire type wire, after its tag.
Effects: fail.
Wire.inner
function Wire.inner(self: Wire, f: Span): WireA reader of a length-delimited field's bytes.
Constants
VARINT
const VARINT = 0The wire types of a field.
FIXED64
const FIXED64 = 1The wire type of a fixed 64-bit word.
BYTES
const BYTES = 2The wire type of length-delimited bytes.
FIXED32
const FIXED32 = 5The wire type of a fixed 32-bit word.