Module Protobuf.Encoder
val error_to_string : error -> string
error_to_string e
converts errore
to its string representation.
exception
Failure of error
val create : unit -> t
create ()
creates a new encoder.
val to_string : t -> string
to_string e
converts the message assembled ine
to a string.
val to_bytes : t -> bytes
to_bytes e
converts the message assembled ine
to bytes.
val varint : int64 -> t -> unit
varint i e
writes a varinti
toe
.
val zigzag : int64 -> t -> unit
zigzag i e
zigzag-encodes a varinti
and writes it toe
.
val bits32 : int32 -> t -> unit
bits32 i e
writes four bytes ofi
toe
.
val bits64 : int64 -> t -> unit
bits64 i e
writes eight bytes ofi
toe
.
val bytes : bytes -> t -> unit
bytes b e
writes a varint indicating length ofb
and thenb
toe
.
val key : (int * payload_kind) -> t -> unit
key (k, pk) e
writes a key and a payload kind toe
.
val encode_exn : ('a -> t -> unit) -> 'a -> bytes
encode_exn f x
≡let e = create () in f x e; to_bytes f
.
val encode : ('a -> t -> unit) -> 'a -> bytes option
encode f x
≡try Some (encode_exn f x) with Failure _ -> None
.