This module implements minimal Google's ProtoBuf primitives.
Types
ProtoBuffer = object options: set[ProtoFlags] buffer*: seq[byte] offset*: int length*: int maxSize*: uint
- Protobuf's message representation object Source Edit
ProtoError {.pure.} = enum VarintDecode, MessageIncomplete, BufferOverflow, MessageTooBig, BadWireType, IncorrectBlob, RequiredFieldMissing
- Source Edit
ProtoField = object index*: int case kind*: ProtoFieldKind of Varint: vint*: uint64 of Fixed64: vfloat64*: float64 of Length: vbuffer*: seq[byte] of Fixed32: vfloat32*: float32 of StartGroup, EndGroup: nil
- Protobuf's message field representation object Source Edit
ProtoFieldKind = enum Varint, Fixed64, Length, StartGroup, EndGroup, Fixed32
- Protobuf's field types enum Source Edit
ProtoFlags = enum WithVarintLength, WithUint32BeLength, WithUint32LeLength
- Protobuf's encoding types Source Edit
ProtoHeader = object wire*: ProtoFieldKind index*: uint64
- Source Edit
ProtoResult[T] = Result[T, ProtoError]
- Source Edit
Consts
SupportedWireTypes = [0, 1, 2, 5]
- Source Edit
Procs
proc finish(pb: var ProtoBuffer) {....raises: [], public, ...tags: [].}
- Prepare protobuf's buffer pb for writing to stream. Source Edit
proc getField(pb: ProtoBuffer; field: int; output: var ProtoBuffer): ProtoResult[ bool] {.inline, ...raises: [], public, ...tags: [].}
- Source Edit
proc getField[T: byte | char](data: ProtoBuffer; field: int; output: var openArray[T]; outlen: var int): ProtoResult[ bool] {....raises: [], public.}
- Source Edit
proc getField[T: ProtoScalar](data: ProtoBuffer; field: int; output: var T): ProtoResult[ bool] {....raises: [], public.}
- Source Edit
proc getField[T: seq[byte] | string](data: ProtoBuffer; field: int; output: var T): ProtoResult[bool] {. ...raises: [], public.}
- Source Edit
proc getPackedRepeatedField[T: ProtoScalar](data: ProtoBuffer; field: int; output: var seq[T]): ProtoResult[bool] {....raises: [], public.}
- Source Edit
proc getRepeatedField[T: ProtoScalar](data: ProtoBuffer; field: int; output: var seq[T]): ProtoResult[bool] {. ...raises: [], public.}
- Source Edit
proc getRepeatedField[T: seq[byte] | string](data: ProtoBuffer; field: int; output: var seq[T]): ProtoResult[bool] {....raises: [], public.}
- Source Edit
proc getRequiredField[T](pb: ProtoBuffer; field: int; output: var T): ProtoResult[ void] {.inline, ...raises: [], public.}
- Source Edit
proc getRequiredRepeatedField[T](pb: ProtoBuffer; field: int; output: var seq[T]): ProtoResult[ void] {.inline, ...raises: [], public.}
- Source Edit
proc initProtoBuffer(data: openArray[byte]; offset = 0; options: set[ProtoFlags] = {}; maxSize = MaxMessageSize): ProtoBuffer {. ...raises: [], public, ...tags: [].}
- Initialize ProtoBuffer with copy of data. Source Edit
proc initProtoBuffer(data: seq[byte]; offset = 0; options: set[ProtoFlags] = {}; maxSize = MaxMessageSize): ProtoBuffer {....raises: [], public, ...tags: [].}
- Initialize ProtoBuffer with shallow copy of data. Source Edit
proc initProtoBuffer(options: set[ProtoFlags] = {}; maxSize = MaxMessageSize): ProtoBuffer {. ...raises: [], public, ...tags: [].}
- Initialize ProtoBuffer with new sequence of capacity cap. Source Edit
proc vsizeof(field: ProtoField): int {.inline, ...raises: [], public, ...tags: [].}
- Returns number of bytes required to store protobuf's field field. Source Edit
proc write(pb: var ProtoBuffer; field: int; value: ProtoBuffer) {.inline, ...raises: [], public, ...tags: [].}
- Encode Protobuf's sub-message value and store it to protobuf's buffer pb with field number field. Source Edit
proc write[T: byte | char](pb: var ProtoBuffer; field: int; value: openArray[T]) {. ...raises: [], public.}
- Source Edit
proc write[T: ProtoScalar](pb: var ProtoBuffer; field: int; value: T) {. ...raises: [], public.}
- Source Edit
proc writePacked[T: ProtoScalar](pb: var ProtoBuffer; field: int; value: openArray[T]) {....raises: [], public.}
- Source Edit
Templates
template checkFieldNumber(i: int)
- Source Edit
template getLen(pb: ProtoBuffer): int
- Source Edit
template getProtoHeader(field: ProtoField): uint64
- Get protobuf's field header integer for field. Source Edit
template getProtoHeader(index: int; wire: ProtoFieldKind): uint64
- Get protobuf's field header integer for index and wire. Source Edit
template getPtr(pb: ProtoBuffer): pointer
- Source Edit
template isEmpty(pb: ProtoBuffer): bool
- Source Edit
template isEnough(pb: ProtoBuffer; length: int): bool
- Source Edit
template toOpenArray(pb: ProtoBuffer): untyped
- Source Edit