[−][src]Struct cjdns_hdr::SwitchHeader
Deserialized switch header struct.
Fields
label: RoutingLabel<u64>
congestion: u8
suppress_errors: bool
version: u8
label_shift: u8
penalty: 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:
- if parsed
version
value is neither 0 nor SwitchHeader::CURRENT_VERSION; - if parsed label number is 0;
- if data input size != SwitchHeader::SIZE.
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]
fn clone(&self) -> SwitchHeader
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for SwitchHeader
[src]
impl Eq for SwitchHeader
[src]
impl PartialEq<SwitchHeader> for SwitchHeader
[src]
fn eq(&self, other: &SwitchHeader) -> bool
[src]
fn ne(&self, other: &SwitchHeader) -> bool
[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,