Struct bp7::bundle::Bundle

source ·
pub struct Bundle {
    pub primary: PrimaryBlock,
    pub canonicals: Vec<CanonicalBlock>,
}
Expand description

Bundle represents a bundle as defined in section 4.2.1. Each Bundle contains one primary block and multiple canonical blocks.

Fields§

§primary: PrimaryBlock§canonicals: Vec<CanonicalBlock>

Implementations§

source§

impl Bundle

source

pub fn new(primary: PrimaryBlock, canonicals: Vec<CanonicalBlock>) -> Bundle

source

pub fn validate(&self) -> Result<(), ErrorList>

Validate bundle and optionally return list of errors.

source

pub fn sort_canonicals(&mut self)

Sort canonical blocks by block number

source

pub fn add_canonical_block(&mut self, cblock: CanonicalBlock)

Automatically assign a block number and add canonical block to bundle

source

pub fn is_administrative_record(&self) -> bool

Checks whether the bundle is an administrative record

source

pub fn payload(&self) -> Option<&ByteBuffer>

Return payload of bundle if an payload block exists and carries data.

source

pub fn set_payload_block(&mut self, payload: CanonicalBlock)

Sets or updates the payload block

source

pub fn set_payload(&mut self, payload: ByteBuffer)

Sets or updates the payload

source

pub fn set_crc(&mut self, crc_type: CrcRawType)

Sets the given CRCType for each block. The crc value is calculated on-the-fly before serializing.

source

pub fn crc_valid(&mut self) -> bool

Check whether a bundle has only valid CRC checksums in all blocks.

source

pub fn calculate_crc(&mut self)

Calculate crc for all blocks.

source

pub fn extension_block_by_type( &self, block_type: CanonicalBlockType ) -> Option<&CanonicalBlock>

Get first extension block matching the block type

source

pub fn extension_block_by_type_mut( &mut self, block_type: CanonicalBlockType ) -> Option<&mut CanonicalBlock>

Get mutable reference for first extension block matching the block type

source

pub fn to_cbor(&mut self) -> ByteBuffer

Serialize bundle as CBOR encoded byte buffer.

source

pub fn to_json(&mut self) -> String

Serialize bundle as JSON encoded string.

source

pub fn id(&self) -> String

ID returns a kind of uniquene representation of this bundle, containing the souce node and creation timestamp. If this bundle is a fragment, the offset is also present.

source

pub fn update_extensions( &mut self, local_node: EndpointID, residence_time: u128 ) -> bool

Update extension blocks such as hop count, bundle age and previous node. Return true if all successful, omit missing blocks. Return false if hop count is exceeded, bundle age exceeds life time or bundle lifetime itself is exceeded

source

pub fn previous_node(&self) -> Option<&EndpointID>

Return the previous node of a bundle should a Previous Node Block exist

Trait Implementations§

source§

impl Clone for Bundle

source§

fn clone(&self) -> Bundle

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Bundle

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Bundle

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Bundle

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Bundle

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Bundle

source§

fn eq(&self, other: &Bundle) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Bundle

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<&[u8]> for Bundle

Deserialize from CBOR byte slice.

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(item: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<String> for Bundle

Deserialize from JSON string.

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(item: String) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Vec<u8>> for Bundle

Deserialize from CBOR byte buffer.

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(item: ByteBuffer) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl StructuralPartialEq for Bundle

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,