buffa-types 0.9.0

Protobuf well-known types for buffa
Documentation

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
  • 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 buffa_types::google::protobuf::Timestamp;
use buffa::Message;

let ts = Timestamp { seconds: 1_000_000_000, nanos: 0, ..Default::default() };
let bytes = ts.encode_to_vec();
let decoded = Timestamp::decode_from_slice(&bytes).unwrap();
assert_eq!(ts, decoded);

Ergonomic helpers

Common Rust type conversions are provided as trait impls:

  • Timestamp ↔ [std::time::SystemTime] (requires std feature)
  • Duration ↔ [std::time::Duration] (requires std feature)
  • Timestamp ↔ [chrono::DateTime] (requires chrono feature; any time zone in, Utc out)
  • Duration ↔ [chrono::TimeDelta] (requires chrono feature)
  • Timestamp ↔ [jiff::Timestamp] (requires jiff feature)
  • Duration ↔ [jiff::SignedDuration] (requires jiff feature)
  • Any::pack / Any::unpack helpers
  • Value constructors: Value::null, From<f64>, From<String>, From<bool>, etc.
  • Wrapper type From/Into impls

Cargo features

  • std (default) — standard-library integration (SystemTime/Duration conversions, std::error::Error). Without it the crate is no_std + alloc.
  • json — proto3 canonical JSON serde for the WKTs.
  • arbitraryarbitrary::Arbitrary derives for fuzzing.
  • chronoTimestampchrono::DateTime and Durationchrono::TimeDelta conversions. no_std-compatible (chrono is pulled with default-features = false).
  • jiffTimestampjiff::Timestamp and Durationjiff::SignedDuration conversions. no_std-compatible (jiff is pulled with default-features = false + alloc).
  • reflect — runtime reflection: the WKT view types implement buffa_descriptor::reflect::ReflectMessage, so a message that has a WKT field can reflect over it. This pulls a buffa-descriptor dependency and requires std (the embedded descriptor pool uses std::sync::OnceLock). If you reach for &view as &dyn ReflectMessage on a WKT view and the compiler says ReflectMessage is not implemented, enable this feature.