Types
A (mutable) encoder.
This encoder can be re-used, see clear.
Error
Sourcetype error = | Overflow of string
Creator
Sourceval create : ?size:int -> unit -> t Clear the content of the internal buffer(s), but does not release memory. This makes the encoder ready to encode another message.
Clears the content and resets internal storage to its initial memory consumption.
This is more costly than clear but can be useful after a very large message was encoded.
Convertion
Extract the content of the encoder to bytes.
Extract the content of the encoder to a string. Call this after encoding a message into the encoder.
Sourceval write_chunks : (bytes -> int -> int -> unit) -> t -> unit write_chunks w e calls the write function w (e.g output oc for some output channel oc) on every chunk inside e. The number of chunks is an implementation detail.
Encoding Functions
These combinators are used by generated code (or user combinators) to encode a OCaml value into the wire representation of protobufs.
key k pk e writes a key and a payload kind to e.
Sourceval nested : ('a -> t -> unit) -> 'a -> t -> unit nested f x e applies f x to an encoder for a message nested in e.
nested f e encodes a zero length empty message
Sourceval int_as_varint : int -> t -> unit int_as_varint i e encodes i in e with Varint encoding
Sourceval int_as_zigzag : int -> t -> unit int_as_zigzag i e encodes i in e with Varint zigzag encoding
Sourceval int32_as_varint : int32 -> t -> unit int32_as_varint i e encodes i in e with Varint encoding
Sourceval int32_as_zigzag : int32 -> t -> unit int32_as_varint i e encodes i in e with Varint zigzag encoding
Sourceval int64_as_varint : int64 -> t -> unit int64_as_varint i e encodes i in e with Varint encoding
Sourceval int64_as_zigzag : int64 -> t -> unit int64_as_varint i e encodes i in e with Varint zigzag encoding
Sourceval int32_as_bits32 : int32 -> t -> unit int32_as_varint i e encodes i in e with Bits32 encoding
Sourceval int64_as_bits64 : int64 -> t -> unit int64_as_varint i e encodes i in e with Bits64 encoding
Sourceval uint32_as_varint : [ `unsigned of int32 ] -> t -> unit Sourceval uint32_as_zigzag : [ `unsigned of int32 ] -> t -> unit Sourceval uint64_as_varint : [ `unsigned of int64 ] -> t -> unit Sourceval uint64_as_zigzag : [ `unsigned of int64 ] -> t -> unit Sourceval uint32_as_bits32 : [ `unsigned of int32 ] -> t -> unit Sourceval uint64_as_bits64 : [ `unsigned of int64 ] -> t -> unit encode b e encodes b in e with Varint encoding
Sourceval float_as_bits32 : float -> t -> unit float_as_bits32 f e encodes f in e with Bits32 encoding
Sourceval float_as_bits64 : float -> t -> unit float_as_bits64 f e encodes f in e with Bits64 encoding
Sourceval int_as_bits32 : int -> t -> unit int_as_bits32 i e encodes i in e with Bits32 encoding TODO : add error handling
Sourceval int_as_bits64 : int -> t -> unit int_as_bits64 i e encodes i in e with Bits64 encoding
Sourceval string : string -> t -> unit string s e encodes s in e
Sourceval bytes : bytes -> t -> unit string s e encodes s in e
Sourceval wrapper_double_value : float option -> t -> unit Sourceval wrapper_float_value : float option -> t -> unit Sourceval wrapper_int64_value : int64 option -> t -> unit Sourceval wrapper_int32_value : int32 option -> t -> unit Sourceval wrapper_bool_value : bool option -> t -> unit Sourceval wrapper_string_value : string option -> t -> unit Sourceval wrapper_bytes_value : bytes option -> t -> unit