Crate prototk

Source
Expand description

§prototk

prototk provides a toolkit for prototcol buffers.

§Status

Maintenance track. The library is considered stable and will be put into maintenance mode if unchanged for one year. The clock was last reset 2023-09-19.

§Scope

This library is about serialization and deserialization of messages. It strives to distil protocol buffers to this:

#[derive(Debug, Default, Message)]
pub enum Error {
    #[prototk(278528, message)]
    #[default]
    Success {
        #[prototk(1, message)]
        core: ErrorCore,
    },
    #[prototk(278529, message)]
    SerializationError {
        #[prototk(1, message)]
        core: ErrorCore,
        #[prototk(2, message)]
        err: prototk::Error,
        #[prototk(3, string)]
        context: String,
    },
    #[prototk(278530, message)]
    UnknownServerName {
        #[prototk(1, message)]
        core: ErrorCore,
        #[prototk(2, string)]
        name: String,
    },
    #[prototk(278531, message)]
    UnknownMethodName {
        #[prototk(1, message)]
        core: ErrorCore,
        #[prototk(2, string)]
        name: String,
    },
    #[prototk(278532, message)]
    RequestTooLarge {
        #[prototk(1, message)]
        core: ErrorCore,
        #[prototk(2, uint64)]
        size: u64,
    },
}

// serialize
let err = Error::UnknownServerName {
    core: ErrorCore::new("robert@rescrv.net", "unknown server name", &UNKOWN_SERVER_NAME_COUNTER),
    name: "FooRpcServer",
};
let buf = stack_pack(err).to_vec()

// deserialize
let up = Unpacker::new(&buf);
let err: Error = up.unpack()?;

§Warts

  • The derive macro’s errors are not the most easy to understand.

§Reserved Field Ranges

The error types in my libraries all have diffrent field numbers. Here is where I track them.

  • 262144..262400 prototk::Error
  • 278528..278784 rpc_pb::Error
  • 294912..295168 macarunes::Error
  • 311296..311552 tuple_key::Error
  • 376832..377088 mani::Error
  • 442368..442624 sst::Error
  • 507904..508160 protoql::Error
  • 573440..573696 paxos_pb::Error

§Maps

Maps are not supported by prototk natively because the typing is too complicated. Make a MapEntry type that has field number 1 for the key and 2 for the value. Put it in a Vec tagged as a message.

§Documentation

The latest documentation is always available at docs.rs.

Modules§

field_types
Field types supported by prototk.

Macros§

tag
A helper macro to construct tags

Structs§

FieldIterator
An iterator over tags and byte strings.
FieldNumber
FieldNumber wraps a u32 and guards it against reserved or invalid field numbers.
FieldPacker
A wrapper type that combines FieldType and FieldPackHelper to make a buffertk::Packable type.
Tag
A protobuf tag has two parts: A field_number and a wire_type.

Enums§

Error
Error captures the possible error conditions for packing and unpacking.
WireType
WireType represents the different protocol buffers wire types.

Constants§

FIRST_FIELD_NUMBER
The first valid field number.
FIRST_RESERVED_FIELD_NUMBER
The first field number reserved by protocol buffers.
LAST_FIELD_NUMBER
The last valid field number.
LAST_RESERVED_FIELD_NUMBER
The last field number reserved by protocol buffers.

Traits§

FieldPackHelper
A FieldPackHelper packs a tag and value in the provided space.
FieldType
A field type is a rust-native type used to convert to and from the wire format.
FieldUnpackHelper
Given a field type that was unpacked, merge it into the rust-native value.
Message
A protocol buffers messsage.

Functions§

unzigzag
The inverse of zigzag.
zigzag
Turn a signed integer into an unsigned integer such that the size is proportional to the input.