Skip to main content

SerializerRegistry

Struct SerializerRegistry 

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

Registry of available serializers

Implementations§

Source§

impl SerializerRegistry

Source

pub fn new() -> Self

Create a new serializer registry with JSON as default

Source

pub fn default_serializer(&self) -> SerializerType

Get the default serializer type

Source

pub fn get(&self, content_type: &str) -> SerializerResult<SerializerType>

Get a serializer by content type

Source

pub fn available() -> Vec<&'static str>

List all available serializers

Source

pub fn detect_format(data: &[u8]) -> Option<SerializerType>

Detect serialization format from raw bytes using magic numbers and heuristics.

This performs best-effort detection by examining byte patterns:

  • JSON: starts with { or [ (after optional whitespace)
  • YAML: starts with --- document marker
  • BSON: 4-byte LE size header matching data length, trailing 0x00
  • MessagePack: binary type markers in the 0x80..=0x9f / 0xc0..=0xdf ranges
  • Protobuf: valid wire-type and field-number in the first tag byte (weak heuristic)

Returns None if the format cannot be determined.

Source

pub fn negotiate( local_preferred: &[SerializerType], remote_supported: &[SerializerType], ) -> Option<SerializerType>

Negotiate the best serialization format between local and remote capabilities.

Iterates through local_preferred in order and returns the first type that also appears in remote_supported. Returns None if there is no overlap between the two sets.

Source

pub fn available_types() -> Vec<SerializerType>

Get all available serializer types based on enabled features.

JSON is always included. Additional types are added when their corresponding Cargo features are enabled.

Trait Implementations§

Source§

impl Default for SerializerRegistry

Source§

fn default() -> Self

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