Skip to main content

SchemaRegistry

Struct SchemaRegistry 

Source
pub struct SchemaRegistry { /* private fields */ }
Expand description

A content-addressed store of schemas, keyed by their 128-bit id.

Implementations§

Source§

impl SchemaRegistry

Source

pub fn new() -> SchemaRegistry

Source

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).

Source

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.

Source

pub fn get(&self, id: u128) -> Option<&Schema>

The schema with this id, if registered.

Source

pub fn contains(&self, id: u128) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn ids(&self) -> impl Iterator<Item = u128> + '_

The ids of every registered schema.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> SchemaRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SchemaRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SchemaRegistry

Source§

fn default() -> SchemaRegistry

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.