Crates.io | anybuf |
lib.rs | anybuf |
version | 0.5.2 |
source | src |
created_at | 2023-04-28 13:41:30.412017 |
updated_at | 2024-12-06 11:33:33.677634 |
description | A minimal, zero dependency proto3 encoder to encode/decode anything. No schemas needed. |
homepage | |
repository | https://github.com/webmaster128/anybuf |
max_upload_size | |
id | 851385 |
size | 132,262 |
A minimal, zero dependency protobuf encoder and decoder to encode/decode anything.
It is designed to create the value
bytes of a protobuf Any
, hence the name.
Due to its low level design, anybuf allows you to do things wrong in many ways and you should have a solid understanding of how protobuf encoding works in general to better understand the API.
The crate anybuf is split in two major components:
anybuf::Anybuf
is a protobuf encoderanybuf::Bufany
is a protobuf decoderAnybuf
instanceEncoding
use anybuf::Anybuf;
let data = Anybuf::new()
.append_uint64(1, 4) // field number 1 gets value 4
.append_string(2, "hello") // field number 2 gets a string
.append_bytes(3, b"hello") // field number 3 gets bytes
.append_message(4, &Anybuf::new().append_bool(3, true)) // field 4 gets a message
.append_repeated_uint64(5, &[23, 56, 192]) // field number 5 is a repeated uint64
.into_vec(); // done
// data is now a serialized protobuf document
Decoding
use anybuf::Bufany;
let deserialized = Bufany::deserialize(&data).unwrap(); // data from above
let id = deserialized.uint64(1).unwrap(); // 4
let title = deserialized.string(2).unwrap(); // "hello"
no_std
supportSince version 0.5.0 there is a default std
feature. If you remove that, the library is built with no_std
support.
As the anybuf maintainers do not require no_std
support this is provided at a best effort basis and might be broken.
[dependencies]
anybuf = { version = "0.5.0", default-features = false }