buffa_reflect/lib.rs
1//! Runtime reflection for the buffa protobuf implementation.
2//!
3//! This crate provides a [`DescriptorPool`] that decodes a serialized
4//! `google.protobuf.FileDescriptorSet` into navigable descriptor handles
5//! ([`MessageDescriptor`], [`FieldDescriptor`], [`EnumDescriptor`],
6//! [`OneofDescriptor`], …) and a one-method [`ReflectMessage`] trait that
7//! every generated buffa message can implement (typically via the
8//! `#[derive(ReflectMessage)]` macro re-exported from this crate).
9//!
10//! # Quick start
11//!
12//! ```no_run
13//! use buffa_reflect::DescriptorPool;
14//!
15//! # fn main() -> Result<(), buffa_reflect::DescriptorError> {
16//! const FDS_BYTES: &[u8] = b""; // produced by `buffa-reflect-build`
17//! let pool = DescriptorPool::decode(FDS_BYTES)?;
18//! for msg in pool.all_messages() {
19//! println!("{}: {} fields", msg.full_name(), msg.fields().len());
20//! }
21//! # Ok(())
22//! # }
23//! ```
24//!
25//! See [`buffa-reflect-build`](https://docs.rs/buffa-reflect-build) for the
26//! companion build-script crate that produces the descriptor set bytes and
27//! decorates generated messages with `#[derive(ReflectMessage)]`.
28
29#![cfg_attr(docsrs, feature(doc_cfg))]
30
31pub mod enumeration;
32pub mod error;
33pub mod field;
34pub mod file;
35pub mod message;
36pub mod oneof;
37pub mod pool;
38mod pool_build;
39pub mod reflect;
40pub mod service;
41
42#[cfg(feature = "dynamic")]
43pub mod dynamic;
44
45// Derive macros and traits live in separate namespaces, so the macro can
46// share the trait's name and users write a single `#[derive(ReflectMessage)]`.
47#[cfg(feature = "derive")]
48pub use buffa_reflect_derive::ReflectMessage;
49
50#[cfg(feature = "serde")]
51pub use crate::dynamic::{DeserializeOptions, SerializeOptions};
52#[cfg(feature = "dynamic")]
53pub use crate::dynamic::{
54 DynamicMessage, MapKey, SetFieldError, UnknownField, UnknownFieldSet, Value,
55};
56#[cfg(feature = "text-format")]
57pub use crate::dynamic::{FormatOptions, ParseError, ParseErrorKind};
58pub use crate::{
59 enumeration::{EnumDescriptor, EnumValueDescriptor},
60 error::DescriptorError,
61 field::{Cardinality, FieldDescriptor, Kind},
62 file::FileDescriptor,
63 message::MessageDescriptor,
64 oneof::OneofDescriptor,
65 pool::DescriptorPool,
66 reflect::{ReflectMessage, ReflectMessageView},
67 service::{MethodDescriptor, ServiceDescriptor},
68};