Hedera.Proto (Hedera v0.2.0)

Copy Markdown View Source

Minimal protobuf (proto3) wire-format encoder — varints, tags, and length-delimited fields. Enough to build the small set of Hedera messages the SDK needs, with no codegen dependency. (A future milestone may switch to protoc-generated modules from the canonical Hedera .proto files.)

Summary

Functions

Encode a length-delimited (wire type 2) field: bytes, strings, or sub-messages.

Decode a protobuf message into a list of {field_number, wire_type, value} — varint values as integers, length-delimited values as binaries. Supports the wire types this SDK emits (0 and 2) plus 64/32-bit (1 and 5).

Decode a packed run of varints (e.g. a proto3 repeated int64 field body).

First value of field in a decoded message, or nil.

Like bytes_field/2, but emit nothing for nil (proto3 omits unset fields).

Encode a signed sint64 (ZigZag) field — used e.g. for transfer amounts.

Encode a field tag (field number + wire type).

Encode a non-negative integer as a base-128 varint.

Encode a varint (wire type 0) field.

Functions

bytes_field(field, bytes)

@spec bytes_field(non_neg_integer(), binary()) :: binary()

Encode a length-delimited (wire type 2) field: bytes, strings, or sub-messages.

decode(bin)

@spec decode(binary()) :: [{non_neg_integer(), 0..5, integer() | binary()}]

Decode a protobuf message into a list of {field_number, wire_type, value} — varint values as integers, length-delimited values as binaries. Supports the wire types this SDK emits (0 and 2) plus 64/32-bit (1 and 5).

decode_varints(bin)

@spec decode_varints(binary()) :: [non_neg_integer()]

Decode a packed run of varints (e.g. a proto3 repeated int64 field body).

field(decoded, field)

@spec field([{non_neg_integer(), 0..5, term()}], non_neg_integer()) ::
  integer() | binary() | nil

First value of field in a decoded message, or nil.

maybe_bytes_field(field, bytes)

@spec maybe_bytes_field(non_neg_integer(), binary() | nil) :: binary()

Like bytes_field/2, but emit nothing for nil (proto3 omits unset fields).

sint64_field(field, value)

@spec sint64_field(non_neg_integer(), integer()) :: binary()

Encode a signed sint64 (ZigZag) field — used e.g. for transfer amounts.

tag(field, wire_type)

@spec tag(non_neg_integer(), 0..5) :: binary()

Encode a field tag (field number + wire type).

varint(n)

@spec varint(non_neg_integer()) :: binary()

Encode a non-negative integer as a base-128 varint.

varint_field(field, value)

@spec varint_field(non_neg_integer(), non_neg_integer()) :: binary()

Encode a varint (wire type 0) field.