Skip to main content

Decode

Trait Decode 

Source
pub trait Decode<'s>:
    Sized
    + Debug
    + PartialEq {
    // Required method
    fn decode<'input, I>(
        input: I,
    ) -> Result<Decoded<Self>, DecodeError<&'input [u8]>>
       where 'input: 's,
             I: Into<&'input [u8]>;
}

Required Methods§

Source

fn decode<'input, I>( input: I, ) -> Result<Decoded<Self>, DecodeError<&'input [u8]>>
where 'input: 's, I: Into<&'input [u8]>,

Decoder trait for decoding the individual fields of the GeoNetworking header Takes binary data as input. The Decoder trait is implemented for all higher-order fields of the GeoNetworking header:

  • Packet
  • BasicHeader
  • CommonHeader
  • Ieee1609Dot2Data (a.k.a. Secured Header)
  • GeoUnicast
  • TopologicallyScopedBroadcast
  • SingleHopBroadcast
  • GeoBroadcast
  • GeoAnycast
  • Beacon
  • LSRequest
  • LSReply
§Usage
let data: &'static [u8] = &[
  0x12, 0x00, 0x15, 0x01, 0x03, 0x81, 0x00, 0x40, 0x03, 0x80, 0x82, 0x02, 0x7c, 0x20,
  0x51, 0x01, 0x00, 0x02, 0x58, 0x01, 0x00, 0x12, 0x52, 0x00, 0x00, 0x3c, 0x00, 0x04,
  0xe5, 0x48, 0x10, 0xc7, 0x2e, 0x71, 0x25, 0xab, 0x00, 0x1f, 0xeb, 0xef, 0x74, 0x05,
  0xf2, 0xaf, 0x27, 0x80, 0x00, 0x00, 0x00,
];
result = BasicHeader::decode(data).unwrap();
assert_eq!(
  result,
  Decoded {
    bytes_consumed: 4,
    decoded: BasicHeader {
        version: 1,
        next_header: NextAfterBasic::SecuredPacket,
        reserved: crate::bits!(0;8),
        lifetime: Lifetime(21),
        remaining_hop_limit: 1
    }
  }
);

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<'s> Decode<'s> for Packet<'s>

Source§

impl<'s> Decode<'s> for BasicHeader

Source§

impl<'s> Decode<'s> for Beacon

Source§

impl<'s> Decode<'s> for CertificateBase<'s>

Source§

impl<'s> Decode<'s> for CommonHeader

Source§

impl<'s> Decode<'s> for GeoAnycast

Source§

impl<'s> Decode<'s> for GeoUnicast

Source§

impl<'s> Decode<'s> for Ieee1609Dot2Data<'s>

Source§

impl<'s> Decode<'s> for LSReply

Source§

impl<'s> Decode<'s> for LSRequest

Source§

impl<'s> Decode<'s> for SingleHopBroadcast

Source§

impl<'s> Decode<'s> for ToBeSignedData<'s>

Source§

impl<'s> Decode<'s> for TopologicallyScopedBroadcast