json or text only.Expand description
Unified type registry for Any expansion and extension brackets — JSON + text.
google.protobuf.Any in both proto3 JSON and textproto needs to know how
to serialize the embedded message by its type URL. Extension fields in
both formats likewise need a lookup by (extendee, number) or
[full_name]. This module is the single install point for both formats:
populate a TypeRegistry with generated register_types(&mut reg) calls,
then set_type_registry once at startup.
The per-format entry types are feature-split so that json and text
are independently enableable — no #[cfg] on struct-literal fields, no
Option<fn> placeholders, no cross-feature implication.
§Usage
use buffa::type_registry::{TypeRegistry, set_type_registry};
let mut reg = TypeRegistry::new();
// Per generated file — registers JSON entries (if generate_json was on)
// and text entries (if generate_text was on), as appropriate:
// my_pkg::register_types(&mut reg);
// Well-known types (hand-registered in buffa-types):
// buffa_types::register_wkt_types(&mut reg);
set_type_registry(reg);§Codegen helpers
any_to_json / any_from_json (under json) and any_encode_text /
any_merge_text (under text) are generic function pointers emitted by
codegen into each message’s entry consts. They compose
Message::decode_from_slice / encode_to_vec with the message’s own
Serialize/Deserialize or TextFormat impl.
Re-exports§
pub use crate::any_registry::JsonAnyEntry;jsonpub use crate::extension_registry::JsonExtEntry;json
Structs§
- Text
AnyEntry text - Registry entry for a single message type’s textproto ↔
Anyconversion. - Text
ExtEntry text - Registry entry for a single extension field’s textproto conversion.
- Type
Registry - Unified registry: JSON
Any+ extension entries (underjson) and textAny+ extension entries (undertext).
Functions§
- any_
encode_ text text Any.valuebytes → textproto: decodeM, write its fields as a{ ... }message body.- any_
from_ json json - JSON →
Any.valuebytes: deserializeMvia itsDeserializeimpl, then encode to wire bytes. - any_
merge_ text text - Textproto
{ ... }body →Any.valuebytes: merge into a freshM, re-encode to wire bytes. - any_
to_ json json Any.valuebytes → JSON: decodeMfrom wire bytes, then serialize viaM’s ownSerializeimpl.- group_
encode_ text text - Textproto encode for a group-encoded extension. Identical body to
message_encode_texton the encode side — only the wire-type of the stored unknown field differs (GroupvsLengthDelimited). - group_
merge_ text text - Textproto merge for a group-encoded extension: consume
{ ... }, re-encode the message’s fields into aGroup(UnknownFields)record. - message_
encode_ text text - Textproto encode for a message-typed extension: decode
Mfrom the unknown fields (merge semantics), write as a{ ... }message body. - message_
merge_ text text - Textproto merge for a message-typed extension: consume
{ ... }, re-encode to aLengthDelimitedunknown-field record. - set_
json_ registry Deprecated - Deprecated: call
set_type_registry. This alias exists for one release cycle to ease migration; the registry now covers text entries too. - set_
type_ registry - Install the global type registry.
Type Aliases§
- AnyText
Merge Fn text TextAnyEntry::text_mergefn-pointer type (factored out for clippy’stype_complexity).- AnyType
Entry Deprecated json - Deprecated alias for
JsonAnyEntry. Retained for one release cycle. - ExtText
Merge Fn text TextExtEntry::text_mergefn-pointer type.- Extension
Registry Entry Deprecated json - Deprecated alias for
JsonExtEntry. Retained for one release cycle. - Json
Registry Deprecated - Deprecated alias for
TypeRegistry. The registry now covers both JSON and text formats.