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.

Note: Encoding/decoding to wire format and byte-typed field operations (set_bytes, get_bytes) require byte array support not yet available in Hew.

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

Traits

Trait MessageMethods

Methods available on a protobuf Message.

Methods

fn set_string(self: Self, field_number: i64, value: string)

Set a string field by field number.

fn get_string(self: 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: Self, field_number: i64, value: i64)

Set a varint (integer) field by field number.

fn get_varint(self: 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: Self, field_number: i64) -> bool

Test whether a field is present in the message.