pub struct SchemaRegistry { /* private fields */ }Expand description
A content-addressed store of schemas, keyed by their 128-bit id.
Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
pub fn new() -> SchemaRegistry
Sourcepub fn register(&mut self, schema: Schema) -> u128
pub fn register(&mut self, schema: Schema) -> u128
Register a schema, returning its id. Idempotent: registering the same content twice is a no-op (same id, same bytes — content-addressed).
Sourcepub fn register_canonical(&mut self, bytes: &[u8]) -> Result<u128>
pub fn register_canonical(&mut self, bytes: &[u8]) -> Result<u128>
Register from canonical bytes (e.g. a message’s inline schema, or a bundle entry): decodes and validates them first, so a malformed or non-canonical blob is rejected rather than stored.
pub fn contains(&self, id: u128) -> bool
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn resolver_for(&self, writer_id: u128, reader: &Schema) -> Result<Resolver>
pub fn resolver_for(&self, writer_id: u128, reader: &Schema) -> Result<Resolver>
Build a Resolver to read a message written with writer_id into
reader — the multi-service payoff. Look up the writer schema here (it
must be registered), then resolve it against the consumer’s own reader
schema, so a hash-only message from a peer becomes fully readable with
schema evolution intact.
writer_id is typically msg.schema_id(). Errors with
Error::SchemaIdMismatch if the writer schema is not registered.
Sourcepub fn to_bundle(&self) -> Vec<u8> ⓘ
pub fn to_bundle(&self) -> Vec<u8> ⓘ
Serialize every registered schema into a portable distribution bundle. Entries are ordered by id, so the bytes are deterministic (diff-friendly) and independent of insertion order.
Sourcepub fn from_bundle(bytes: &[u8]) -> Result<SchemaRegistry>
pub fn from_bundle(bytes: &[u8]) -> Result<SchemaRegistry>
Load a registry from a distribution bundle. Every schema is decoded and validated (and thereby its id recomputed from its bytes), so a tampered bundle is rejected rather than trusted.
Sourcepub fn merge_bundle(&mut self, bytes: &[u8]) -> Result<usize>
pub fn merge_bundle(&mut self, bytes: &[u8]) -> Result<usize>
Merge a distribution bundle into this registry, returning how many schemas were newly added (already-present ids are skipped — idempotent).
Trait Implementations§
Source§impl Clone for SchemaRegistry
impl Clone for SchemaRegistry
Source§fn clone(&self) -> SchemaRegistry
fn clone(&self) -> SchemaRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more