Serialization

Trait Serialization 

Source
pub trait Serialization {
    const HEAD: u16 = 0xAAAA;
    const TAIL: u16 = 0x5555;
    const SIZE: usize = 0;

    // Required method
    fn from_bytestream(
        bytestream: &Vec<u8>,
        pos: &mut usize,
    ) -> Result<Self, SerializationError>
       where Self: Sized;

    // Provided methods
    fn guess_size(
        stream: &Vec<u8>,
        pos: usize,
        offset: usize,
    ) -> Result<(usize, usize, usize), SerializationError> { ... }
    fn verify_fixed(
        stream: &Vec<u8>,
        pos: &mut usize,
    ) -> Result<(), SerializationError> { ... }
    fn from_bytestream_alt(
        bytestream: &Vec<u8>,
        pos: &mut usize,
    ) -> Result<Self, SerializationError>
       where Self: Sized { ... }
    fn to_bytestream(&self) -> Vec<u8>  { ... }
}
Expand description

Encode/decode structs to Vec::<u8> to write to a file or send over the network

Provided Associated Constants§

Source

const HEAD: u16 = 0xAAAA

Byte marker to mark beginning of payload

Source

const TAIL: u16 = 0x5555

Byte marker to mark end of payload

Source

const SIZE: usize = 0

The SIZE is the size of the serialized bytestream INCLUDING 4 bytes for head and tail bytes. In case the struct does NOT HAVE a fixed size, SIZE will be 0 (so default value of the trait

Required Methods§

Source

fn from_bytestream( bytestream: &Vec<u8>, pos: &mut usize, ) -> Result<Self, SerializationError>
where Self: Sized,

Decode a serializable from a bytestream

§Arguments:
  • bytestream : bytes including the ones which should be decoded
  • pos : first byte in the bytestream which is part of the expected payload

Provided Methods§

Source

fn guess_size( stream: &Vec<u8>, pos: usize, offset: usize, ) -> Result<(usize, usize, usize), SerializationError>

Guess the size of te packet. This can be a preformance issue if te offset position is far off

This will not advance the pos marker!

Source

fn verify_fixed( stream: &Vec<u8>, pos: &mut usize, ) -> Result<(), SerializationError>

Verify that the serialized representation of the struct has the correct size, including header + footer.

Will panic for variable sized structs.

Source

fn from_bytestream_alt( bytestream: &Vec<u8>, pos: &mut usize, ) -> Result<Self, SerializationError>
where Self: Sized,

Decode a serializable from a bytestream. This provides an alternative method to get the packet. If not implemented, it will be the same as from_bytestream.

§Arguments:
  • bytestream : bytes including the ones which should be decoded
  • pos : first byte in the bytestream which is part of the expected payload
Source

fn to_bytestream(&self) -> Vec<u8>

Encode a serializable to a bytestream

This shall return a representation of the struct in such a way that to_bytestream and from_bytestream are inverse operations.

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§

Source§

impl Serialization for TofResponse

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 9

Source§

impl Serialization for RBCalibrationFlightT

Source§

const SIZE: usize

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

impl Serialization for RBCalibrationFlightV

Source§

const SIZE: usize

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

impl Serialization for RBCalibrations

Source§

const SIZE: usize

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

impl Serialization for RBEvent

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

impl Serialization for RBEventHeader

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 30

Source§

impl Serialization for RBWaveform

Source§

const HEAD: u16 = 43690

Source§

const TAIL: u16 = 21845

Source§

const SIZE: usize

Source§

impl Serialization for TelemetryEvent

Source§

impl Serialization for TofEvent

Source§

const HEAD: u16 = 43690

Source§

const TAIL: u16 = 21845

Source§

impl Serialization for TofHit

Source§

const HEAD: u16 = 61680

Source§

const TAIL: u16 = 3855

Source§

const SIZE: usize = 44

Source§

impl Serialization for CPUMoniData

Source§

const SIZE: usize = 41

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

impl Serialization for DataSinkHB

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 84

Source§

impl Serialization for EventBuilderHB

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 156

Source§

impl Serialization for MasterTriggerHB

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 111

Source§

impl Serialization for LTBMoniData

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize

Source§

impl Serialization for MtbMoniData

Source§

const SIZE: usize = 24

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

impl Serialization for PAMoniData

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize

Source§

impl Serialization for PBMoniData

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize

Source§

impl Serialization for RBMoniData

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize

Source§

impl Serialization for AckBfsw

Source§

const HEAD: u16 = 0x90eb

Source§

const TAIL: u16 = 0x0000

Source§

const SIZE: usize = 13

Source§

impl Serialization for MagnetoMeter

Source§

const HEAD: u16 = 0x90eb

Source§

const TAIL: u16 = 0x0000

Source§

const SIZE: usize = 57

Source§

impl Serialization for TelemetryPacket

Source§

const HEAD: u16 = 0

Source§

const TAIL: u16 = 0

Source§

const SIZE: usize = 0

Source§

impl Serialization for TelemetryPacketHeader

Source§

const HEAD: u16 = 0x90eb

Source§

const TAIL: u16 = 0x0000

Source§

const SIZE: usize = 13

Source§

impl Serialization for TofPacket

Source§

const HEAD: u16 = 0xaaaa

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 0

Source§

impl Serialization for TrackerDAQHSKPacket

Source§

impl Serialization for TrackerDAQTempPacket

Source§

impl Serialization for TrackerEventIDEchoPacket

Source§

impl Serialization for TrackerTempLeakPacket

Source§

impl Serialization for TrackerHeader

Source§

const SIZE: usize = 17

Source§

impl Serialization for TofCommand

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

impl Serialization for AnalysisEngineConfig

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 65

Source§

impl Serialization for DataPublisherConfig

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 24

Source§

impl Serialization for LTBThresholdConfig

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 17

Source§

impl Serialization for PreampBiasConfig

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 69

Source§

impl Serialization for RBChannelMaskConfig

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 14

Source§

impl Serialization for TOFEventBuilderConfig

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 46

Source§

impl Serialization for TofRBConfig

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 25

Source§

impl Serialization for TofRunConfig

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 12

Source§

impl Serialization for TriggerConfig

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 26

Source§

impl Serialization for TofDetectorStatus

Source§

const HEAD: u16 = 0xAAAA

Source§

const TAIL: u16 = 0x5555

Source§

const SIZE: usize = 44

Source§

impl Serialization for PanicPacket

Source§

const HEAD: u16 = 43690

Source§

const TAIL: u16 = 21845

Source§

impl Serialization for LiftofRBConfig

Source§

const HEAD: u16 = 43690

Source§

const TAIL: u16 = 21845

Source§

const SIZE: usize = 24

Source§

impl Serialization for CRFrame

Source§

impl Serialization for CRFrameObject