pub struct SerializerRegistry { /* private fields */ }Expand description
Registry of available serializers
Implementations§
Source§impl SerializerRegistry
impl SerializerRegistry
Sourcepub fn default_serializer(&self) -> SerializerType
pub fn default_serializer(&self) -> SerializerType
Get the default serializer type
Sourcepub fn get(&self, content_type: &str) -> SerializerResult<SerializerType>
pub fn get(&self, content_type: &str) -> SerializerResult<SerializerType>
Get a serializer by content type
Sourcepub fn detect_format(data: &[u8]) -> Option<SerializerType>
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..=0xdfranges - Protobuf: valid wire-type and field-number in the first tag byte (weak heuristic)
Returns None if the format cannot be determined.
Sourcepub fn negotiate(
local_preferred: &[SerializerType],
remote_supported: &[SerializerType],
) -> Option<SerializerType>
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.
Sourcepub fn available_types() -> Vec<SerializerType>
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§
Auto Trait Implementations§
impl Freeze for SerializerRegistry
impl RefUnwindSafe for SerializerRegistry
impl Send for SerializerRegistry
impl Sync for SerializerRegistry
impl Unpin for SerializerRegistry
impl UnsafeUnpin for SerializerRegistry
impl UnwindSafe for SerializerRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more