[][src]Struct rust_ipv8::serialization::Packet

pub struct Packet(pub Vec<u8>);

The packet struct containing the bytes of a packet in a Vec<u8>.

Methods

impl Packet[src]

pub fn new(header: Header) -> Result<Self, Box<dyn Error>>[src]

Creates a new packet with a given header.

pub fn raw(&self) -> &[u8][src]

Extracts the raw byte contents from a packet.

pub fn sign(self, keypair: &KeyPair) -> Result<Self, Box<dyn Error>>[src]

Signs a packet. After this, new payloads must under no circumstances be added as this will break the verification process on the receiving end. There is no check for this by design for a speed boost (though this may or may not be revisited later). Sign deliberately consumes self and returns it again so it can be assigned to a new, immutable variable to never be changed again.

Verification of this signature can only happen when a public key is known at the receiving end. The user of the rust-ipv8 library is responsible for this to already have been packed into the final packet or alternatively already known by the receiver.

To verify signatures first transform the Packet into a PacketIterator with Packet.deserialize_multiple and then use the PacketIterator.verify() or PacketIterator.verify_with() method.

pub fn start_deserialize(self) -> PacketDeserializer[src]

Deserializes a stream of bytes into ipv8 payloads.

pub fn add<T>(&mut self, obj: &T) -> Result<(), Box<ErrorKind>> where
    T: Ipv8Payload + Serialize
[src]

Adds a payload to a packet. This serializes payloads.

Trait Implementations

impl PartialEq<Packet> for Packet[src]

impl Clone for Packet[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Packet[src]

impl Serialize for Packet[src]

impl<'de> Deserialize<'de> for Packet[src]

Auto Trait Implementations

impl Unpin for Packet

impl Sync for Packet

impl Send for Packet

impl RefUnwindSafe for Packet

impl UnwindSafe for Packet

Blanket Implementations

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

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

type Owned = T

The resulting type after obtaining ownership.

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

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.

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

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

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

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