Module Protobuf.Decoder
type error
=
|
Incomplete
|
Overlong_varint
|
Malformed_field
|
Overflow of string
|
Unexpected_payload of string * payload_kind
|
Missing_field of string
|
Malformed_variant of string
Type of failures possible while decoding.
val error_to_string : error -> string
error_to_string e
converts errore
to its string representation.
exception
Failure of error
val of_bytes : bytes -> t
of_bytes b
creates a decoder positioned at start of bytesb
.
val of_string : string -> t
of_string s
creates a decoder positioned at start of strings
.
val at_end : t -> bool
at_end d
returnstrue
ifd
has exhausted its input, andfalse
otherwise.
val skip : t -> payload_kind -> unit
skip d pk
skips the next value of kindpk
ind
. If skipping the value would exhaust input ofd
, raisesEncoding_error Incomplete
.
val varint : t -> int64
varint d
reads a varint fromd
. Ifd
has exhausted its input, raisesFailure Incomplete
.
val zigzag : t -> int64
zigzag d
reads a varint fromd
and zigzag-decodes it. Ifd
has exhausted its input, raisesFailure Incomplete
.
val bits32 : t -> int32
bits32 d
reads four bytes fromd
. Ifd
has exhausted its input, raisesFailure Incomplete
.
val bits64 : t -> int64
bits64 d
reads eight bytes fromd
. Ifd
has exhausted its input, raisesFailure Incomplete
.
val bytes : t -> bytes
bytes d
reads a varint indicating length and then that much bytes fromd
. Ifd
has exhausted its input, raisesFailure Incomplete
.
val nested : t -> t
nested d
returns a decoder for a message nested ind
. If reading the message would exhaust input ofd
, raisesFailure Incomplete
.
val key : t -> (int * payload_kind) option
key d
reads a key and a payload kind fromd
. Ifd
has exhausted its input when the function is called, returnsNone
. Ifd
has exhausted its input while reading, raisesFailure Incomplete
. If the payload kind is unknown, raisesFailure Malformed_field
.
val decode_exn : (t -> 'a) -> bytes -> 'a
decode_exn f b
≡f (create b)
.
val decode : (t -> 'a) -> bytes -> 'a option
decode f b
≡try Some (decode_exn f b) with Failure _ -> None
val int_of_int32 : string -> int32 -> int
int_of_int32 fld v
returnsv
truncated toint
. If the value doesn't fit in the range ofint
, raisesFailure (Overflow fld)
.
val int_of_int64 : string -> int64 -> int
int_of_int64 fld v
returnsv
truncated toint
. If the value doesn't fit in the range ofint
, raisesFailure (Overflow fld)
.