[][src]Struct cjdns_hdr::SwitchHeader

pub struct SwitchHeader {
    pub label: RoutingLabel<u64>,
    pub congestion: u8,
    pub suppress_errors: bool,
    pub version: u8,
    pub label_shift: u8,
    pub penalty: u16,
}

Deserialized switch header struct.

Fields

label: RoutingLabel<u64>congestion: u8suppress_errors: boolversion: u8label_shift: u8penalty: u16

Implementations

impl SwitchHeader[src]

pub const SIZE: usize[src]

Size of serialized SwitchHeader

pub const CURRENT_VERSION: u8[src]

Current version of SwitchHeader which is automatically set, if version is not specified (i.e. == 0) during serialization.

pub fn parse(data: &[u8]) -> Result<Self, ParseError>[src]

Parses raw bytes into SwitchHeader struct.

Results in error in several situations:

SwitchHeader bytes have a following structure: 8 bytes for routing label, one byte for congestion value and suppress error flag, also a byte for version and label shift values and 2 bytes for penalty value. Congestion value always takes 7 bits. Last bit of congestion byte is suppress error flag. Version value takes last 2 bits of a sharing with label shift value byte. First 6 bits of the byte "belong" to label_shift.

pub fn serialize(&self) -> Result<Vec<u8>, SerializeError>[src]

Serializes SwitchHeader instance.

SwitchHeader type can be instantiated directly, without using parse method. That's why serialization can result in errors. If header version isn't equal to 0 or to SwitchHeader::CURRENT_VERSION, then serialization fails. Also serialization fails if label_shift value takes more than 6 bits (i.e. > 63), or if congestion value takes more than 7 bits (i.e. > 127).

If SwitchHeader was instantiated with 0 version, header will be parsed with version equal to SwitchHeader::CURRENT_VERSION.

Trait Implementations

impl Clone for SwitchHeader[src]

impl Debug for SwitchHeader[src]

impl Eq for SwitchHeader[src]

impl PartialEq<SwitchHeader> for SwitchHeader[src]

impl StructuralEq for SwitchHeader[src]

impl StructuralPartialEq for SwitchHeader[src]

Auto Trait Implementations

impl RefUnwindSafe for SwitchHeader

impl Send for SwitchHeader

impl Sync for SwitchHeader

impl Unpin for SwitchHeader

impl UnwindSafe for SwitchHeader

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.