Module std.encoding.protobuf
Protocol Buffers message construction.
Build and inspect Protocol Buffers messages using a field-number based API. Supports string and varint (integer) fields.
This API supports in-memory string and varint fields. It does not expose wire-format encoding, decoding, or byte-typed fields.
Examples
import std.encoding.protobuf;
fn main() {
let msg = protobuf.new();
msg.set_varint(1, 42);
msg.set_string(2, "hello");
let val = msg.get_string(2);
println(val);
msg.close();
}
Contents
Functions
Function new
pub fn new() -> Message
Create a new empty Protocol Buffers message.
Examples
import std.encoding.protobuf;
fn main() {
let msg = protobuf.new();
msg.set_varint(1, 100);
msg.close();
}
Types
Struct Message
Fields
- handle: MessageHandle
Methods
fn set_string(self, field_number: i64, value: string)
Set a string field by field number.
fn get_string(self, field_number: i64) -> string
Get a string field by field number.
Returns an empty string if the field is not set.
fn set_varint(self, field_number: i64, value: i64)
Set a varint (integer) field by field number.
fn get_varint(self, field_number: i64, fallback: i64) -> i64
Get a varint (integer) field by field number.
Returns fallback if the field is not set.
fn has_field(self, field_number: i64) -> bool
Test whether a field is present in the message.
Inherent methods
impl Message
fn close(consume self)
Release this message early.