Expand description
protobuf support for sval
.
This library implements a binary encoding for sval::Value
s that’s compatible with the
protobuf wire format.
This library doesn’t depend on protoc
or any code generation tools; any implementation of
sval::Value
can be encoded. You can use it in cases where standard code generation is either
impractical or produces undesirable results. It supports some more niche use-cases like embedding
already encoded messages into others without needing to parse them first.
This library only supports encoding.
§Specifics
This section uses protoscope syntax for encoded messages.
§Messages
If you #[derive(Value)]
, your structs are encoded as messages:
#[derive(Value)]
pub struct Record<'a> {
id: i32,
title: &'a str,
data: &'a str,
}
Record {
id: 42,
title: "My Message",
data: "Some amazing content",
}
1: 42
2: {"My Message"}
3: {"Some amazing content"}
Specify an #[sval(index)]
on fields to set the field number explicitly:
#[derive(Value)]
pub struct ManuallyIndexed<'a> {
#[sval(index = 3)]
id: i32,
#[sval(index = 7)]
title: &'a str,
}
ManuallyIndexed {
id: 42,
title: "My Message",
}
3: 42
7: {"My Message"}
Anonymous tuples are also messages:
(
42,
"My Message",
"Some amazing content",
)
1: 42
2: {"My Message"}
3: {"Some amazing content"}
128bit numbers are always encoded as a 16 byte buffer with the little-endian bytes of the value.
Re-exports§
pub use crate::buf::Capacity;
Modules§
Structs§
- Proto
BufStream - An
sval::Stream
that encodes into the protobuf wire format. - Proto
BufStream Reusable - The re-usable internals of a
ProtoBufStream
that can optimize a later encoding.
Functions§
- stream_
to_ protobuf - Encode a value to the protobuf wire format.