Protobuf well-known types for buffa.
This crate provides Rust types for Google's well-known .proto types:
- [
google::protobuf::Timestamp] — Unix timestamp with nanosecond precision - [
google::protobuf::Duration] — Signed duration with nanosecond precision - [
google::protobuf::Any] — Any value with an attached type URL - [
google::protobuf::Struct] / [google::protobuf::Value] / [google::protobuf::ListValue] — JSON-like dynamic values - [
google::protobuf::FieldMask] — Specifies a subset of fields referenced in a message - [
google::protobuf::Empty] — A generic empty message - [
google::protobuf::Api] / [google::protobuf::Type] / [google::protobuf::Enum] / [google::protobuf::SourceContext] — API and type descriptors used by googleapis (api.proto,type.proto,source_context.proto), with their parts [google::protobuf::Method], [google::protobuf::Mixin], [google::protobuf::Field], [google::protobuf::EnumValue], and [google::protobuf::Option]. That last one shadows the preludeOptionin any module that glob-importsgoogle::protobuf::*; it is not re-exported at the crate root. - Wrapper types: [
google::protobuf::BoolValue], [google::protobuf::Int32Value], [google::protobuf::Int64Value], [google::protobuf::UInt32Value], [google::protobuf::UInt64Value], [google::protobuf::FloatValue], [google::protobuf::DoubleValue], [google::protobuf::StringValue], [google::protobuf::BytesValue]
Usage
use Timestamp;
use Message;
let ts = Timestamp ;
let bytes = ts.encode_to_vec;
let decoded = decode_from_slice.unwrap;
assert_eq!;
Ergonomic helpers
Common Rust type conversions are provided as trait impls:
Timestamp↔ [std::time::SystemTime] (requiresstdfeature)Duration↔ [std::time::Duration] (requiresstdfeature)Timestamp↔ [chrono::DateTime] (requireschronofeature; any time zone in,Utcout)Duration↔ [chrono::TimeDelta] (requireschronofeature)Timestamp↔ [jiff::Timestamp] (requiresjifffeature)Duration↔ [jiff::SignedDuration] (requiresjifffeature)Any::pack/Any::unpackhelpersValueconstructors:Value::null,From<f64>,From<String>,From<bool>, etc.- Wrapper type
From/Intoimpls
Cargo features
std(default) — standard-library integration (SystemTime/Durationconversions,std::error::Error). Without it the crate isno_std+alloc.json— proto3 canonical JSON serde for the JSON-mappable WKTs (Timestamp,Duration,Any,Struct/Value/ListValue,FieldMask,Empty, wrappers).Api/Type/Enum/SourceContextand the messages they contain have no serde impls; ajson = truemessage embedding one of them does not compile.arbitrary—arbitrary::Arbitraryderives for fuzzing.chrono—Timestamp↔chrono::DateTimeandDuration↔chrono::TimeDeltaconversions.no_std-compatible (chronois pulled withdefault-features = false).jiff—Timestamp↔jiff::TimestampandDuration↔jiff::SignedDurationconversions.no_std-compatible (jiffis pulled withdefault-features = false+alloc).reflect— runtime reflection: the WKT view types implementbuffa_descriptor::reflect::ReflectMessage, so a message that has a WKT field can reflect over it. This pulls abuffa-descriptordependency and requiresstd(the embedded descriptor pool usesstd::sync::OnceLock). If you reach for&view as &dyn ReflectMessageon a WKT view and the compiler saysReflectMessageis not implemented, enable this feature.