Trait SerializeStruct

Source
pub trait SerializeStruct {
    type Ok;
    type Error: Error;

    // Required methods
    fn serialize_field<T>(
        &mut self,
        key: &'static str,
        value: &T,
    ) -> Result<(), Self::Error>
       where T: ?Sized + Serialize;
    fn serialize_fixed_array_field<V, T>(
        &mut self,
        key: &'static str,
        value: V,
        size: TypeSize,
    ) -> Result<(), Self::Error>
       where V: AsRef<[T]> + Serialize,
             T: Serialize;
    fn end(self) -> Result<Self::Ok, Self::Error>;

    // Provided methods
    fn skip_field<T>(
        &mut self,
        key: &'static str,
        value: &T,
    ) -> Result<(), Self::Error>
       where T: ?Sized + Serialize { ... }
    fn pad_field<T>(
        &mut self,
        x86_pads: &T,
        x64_pads: &T,
    ) -> Result<(), Self::Error>
       where T: ?Sized + AsRef<[u8]> { ... }
    fn skip_fixed_array_field<V, T>(
        &mut self,
        key: &'static str,
        value: V,
        size: TypeSize,
    ) -> Result<(), Self::Error>
       where V: AsRef<[T]> + Serialize,
             T: Serialize { ... }
    fn serialize_array_field<V, T>(
        &mut self,
        key: &'static str,
        value: V,
        size: TypeSize,
    ) -> Result<(), Self::Error>
       where V: AsRef<[T]> + Serialize,
             T: Serialize { ... }
    fn skip_array_field<V, T>(
        &mut self,
        key: &'static str,
        value: V,
        size: TypeSize,
    ) -> Result<(), Self::Error>
       where V: AsRef<[T]> + Serialize,
             T: Serialize { ... }
}
Expand description

Returned from Serializer::serialize_struct.

The example data format presented on the website demonstrates an implementation of SerializeStruct for a basic JSON data format.

§Flatten is unsupportable

If the parent is a ptr type, the process of simply writing the parent cannot be used as it is because the data writing of the ptr destination is waiting after the writing of all fields. Therefore, serialize of the parent struct cannot be reused.

Required Associated Types§

Source

type Ok

Must match the Ok type of our Serializer.

Source

type Error: Error

Must match the Error type of our Serializer.

Required Methods§

Source

fn serialize_field<T>( &mut self, key: &'static str, value: &T, ) -> Result<(), Self::Error>
where T: ?Sized + Serialize,

Serialize a struct field.

Source

fn serialize_fixed_array_field<V, T>( &mut self, key: &'static str, value: V, size: TypeSize, ) -> Result<(), Self::Error>
where V: AsRef<[T]> + Serialize, T: Serialize,

Serialize a struct field for fixed array.

  • XML: add numelements attribute to hkparam and write array contents.(same as hkArray)
  • Bytes: write each bytes.
Source

fn end(self) -> Result<Self::Ok, Self::Error>

Finish serializing a struct.

Provided Methods§

Source

fn skip_field<T>( &mut self, key: &'static str, value: &T, ) -> Result<(), Self::Error>
where T: ?Sized + Serialize,

Process for fields with SERIALIZE_IGNORED flag.

  • XML: Replaced by a comment and the actual data is not displayed.
  • Bytes: the data itself is read/written

The default implementation does nothing.

Source

fn pad_field<T>( &mut self, x86_pads: &T, x64_pads: &T, ) -> Result<(), Self::Error>
where T: ?Sized + AsRef<[u8]>,

Processing for padding to serialize binary data

The default implementation does nothing.

Source

fn skip_fixed_array_field<V, T>( &mut self, key: &'static str, value: V, size: TypeSize, ) -> Result<(), Self::Error>
where V: AsRef<[T]> + Serialize, T: Serialize,

Process for fields with SERIALIZE_IGNORED flag.

The default implementation same as skip_field

Source

fn serialize_array_field<V, T>( &mut self, key: &'static str, value: V, size: TypeSize, ) -> Result<(), Self::Error>
where V: AsRef<[T]> + Serialize, T: Serialize,

Serialize a struct field for array.

  • XML: add numelements attribute to hkparam and write vec contents.
  • Bytes: Alloc meta(ptr size + size + capAndFlags) bytes. (x86: 12, x64: 16) & Serialize pointed data.
Source

fn skip_array_field<V, T>( &mut self, key: &'static str, value: V, size: TypeSize, ) -> Result<(), Self::Error>
where V: AsRef<[T]> + Serialize, T: Serialize,

Process for fields with SERIALIZE_IGNORED flag.

The default implementation same as skip_field

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§