Skip to main content

Module proto

Module proto 

Source
Expand description

Lightweight protobuf wire-format encoder/decoder.

Produces bytes fully compatible with the Protocol Buffers binary wire format (no .proto file or code-generation required). This makes protobuf the native serialisation layer for Oxide guest applications.

§Encoding

use oxide_sdk::proto::ProtoEncoder;

let data = ProtoEncoder::new()
    .string(1, "alice")
    .uint64(2, 42)
    .bool(3, true)
    .bytes(4, &[0xCA, 0xFE])
    .finish();

§Decoding

use oxide_sdk::proto::ProtoDecoder;

let mut decoder = ProtoDecoder::new(&data);
while let Some(field) = decoder.next() {
    match field.number {
        1 => log(&format!("name = {}", field.as_str())),
        2 => log(&format!("age  = {}", field.as_u64())),
        _ => {}
    }
}

Structs§

ProtoDecoder
Iterates over protobuf-encoded fields one at a time.
ProtoEncoder
Builds a protobuf-compatible binary message field by field.
ProtoField
A single decoded protobuf field.