Trait hotfix_encoding::field_access::FieldType
source · pub trait FieldType<'a>where
Self: Sized,{
type Error;
type SerializeSettings: Default;
// Required methods
fn serialize_with<B>(
&self,
buffer: &mut B,
settings: Self::SerializeSettings
) -> usize
where B: Buffer;
fn deserialize(data: &'a [u8]) -> Result<Self, Self::Error>;
// Provided methods
fn serialize<B>(&self, buffer: &mut B) -> usize
where B: Buffer { ... }
fn deserialize_lossy(data: &'a [u8]) -> Result<Self, Self::Error> { ... }
fn to_bytes(&self) -> Vec<u8> { ... }
fn to_string(&self) -> String { ... }
}
Expand description
Provides (de)serialization logic for a Rust type as FIX field values.
See the field_types
module for more information.
Required Associated Types§
sourcetype SerializeSettings: Default
type SerializeSettings: Default
A type with values that customize the serialization algorithm, e.g. padding information.
Required Methods§
sourcefn serialize_with<B>(
&self,
buffer: &mut B,
settings: Self::SerializeSettings
) -> usizewhere
B: Buffer,
fn serialize_with<B>( &self, buffer: &mut B, settings: Self::SerializeSettings ) -> usizewhere B: Buffer,
Writes self
to buffer
using custom serialization settings
.
sourcefn deserialize(data: &'a [u8]) -> Result<Self, Self::Error>
fn deserialize(data: &'a [u8]) -> Result<Self, Self::Error>
Parses and deserializes from data
.
Provided Methods§
sourcefn serialize<B>(&self, buffer: &mut B) -> usizewhere
B: Buffer,
fn serialize<B>(&self, buffer: &mut B) -> usizewhere B: Buffer,
Writes self
to buffer
using default settings.
sourcefn deserialize_lossy(data: &'a [u8]) -> Result<Self, Self::Error>
fn deserialize_lossy(data: &'a [u8]) -> Result<Self, Self::Error>
Like FieldType::deserialize
, but it’s allowed to skip some amount of
input checking. Invalid inputs might not trigger errors and instead be
deserialized as random values.
Safety
This method remains 100% safe even on malformed inputs.
sourcefn to_string(&self) -> String
fn to_string(&self) -> String
Allocates a String
representation of self
, using FieldType::to_bytes
.
Panics
This function will panic if the underlying byte representation is not
valid UTF-8. As such, you should only ever use this function for
FieldType
implementors that are guaranteed to be representable with
valid UTF-8 (like numbers with ASCII digits).