Packet

Enum Packet 

Source
pub enum Packet {
    Rrq {
        filename: String,
        mode: String,
        options: Vec<TransferOption>,
    },
    Wrq {
        filename: String,
        mode: String,
        options: Vec<TransferOption>,
    },
    Data {
        block_num: u16,
        data: Vec<u8>,
    },
    Ack(u16),
    Error {
        code: ErrorCode,
        msg: String,
    },
    Oack(Vec<TransferOption>),
}
Expand description

Packet enum represents the valid TFTP packet types.

This enum has function implementaions for serializing Packets into Vec<u8>s and deserializing u8 slices to Packets.

§Example

use tftpd::Packet;

let packet = Packet::Data { block_num: 15, data: vec![0x01, 0x02, 0x03] };

assert_eq!(packet.serialize().unwrap(), vec![0x00, 0x03, 0x00, 0x0F, 0x01, 0x02, 0x03]);
assert_eq!(Packet::deserialize(&[0x00, 0x03, 0x00, 0x0F, 0x01, 0x02, 0x03]).unwrap(), packet);

Variants§

§

Rrq

Read Request struct

Fields

§filename: String

Name of the requested file

§mode: String

Transfer mode

§options: Vec<TransferOption>

Transfer options

§

Wrq

Write Request struct

Fields

§filename: String

Name of the requested file

§mode: String

Transfer mode

§options: Vec<TransferOption>

Transfer options

§

Data

Data struct

Fields

§block_num: u16

Block number

§data: Vec<u8>

Data

§

Ack(u16)

Acknowledgement tuple with block number

§

Error

Error struct

Fields

§code: ErrorCode

Error code

§msg: String

Error message

§

Oack(Vec<TransferOption>)

Option acknowledgement tuple with transfer options

Implementations§

Source§

impl Packet

Source

pub fn deserialize(buf: &[u8]) -> Result<Packet, Box<dyn Error>>

Deserializes a u8 slice into a Packet.

Source

pub fn serialize(&self) -> Result<Vec<u8>, &'static str>

Serializes a Packet into a Vec<u8>.

Trait Implementations§

Source§

impl Debug for Packet

Source§

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

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

impl PartialEq for Packet

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Packet

Auto Trait Implementations§

§

impl Freeze for Packet

§

impl RefUnwindSafe for Packet

§

impl Send for Packet

§

impl Sync for Packet

§

impl Unpin for Packet

§

impl UnwindSafe for Packet

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.