Skip to main content

PacketField

Trait PacketField 

Source
pub trait PacketField: Sized {
    // Required methods
    fn write_to(&self, buf: &mut Vec<u8>);
    fn read_from(buf: &[u8], pos: &mut usize) -> Option<Self>;
}
Expand description

Encode/decode a single field to/from a byte buffer.

Implemented for the types supported by packet!: bool, i32, i64, u32, u64, f32, f64, String, Vec<u8>.

Required Methods§

Source

fn write_to(&self, buf: &mut Vec<u8>)

Source

fn read_from(buf: &[u8], pos: &mut usize) -> Option<Self>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl PacketField for String

Source§

fn write_to(&self, buf: &mut Vec<u8>)

Source§

fn read_from(buf: &[u8], pos: &mut usize) -> Option<String>

Source§

impl PacketField for Vec<u8>

Source§

fn write_to(&self, buf: &mut Vec<u8>)

Source§

fn read_from(buf: &[u8], pos: &mut usize) -> Option<Vec<u8>>

Source§

impl PacketField for bool

Source§

fn write_to(&self, buf: &mut Vec<u8>)

Source§

fn read_from(buf: &[u8], pos: &mut usize) -> Option<bool>

Source§

impl PacketField for f32

Source§

fn write_to(&self, buf: &mut Vec<u8>)

Source§

fn read_from(buf: &[u8], pos: &mut usize) -> Option<f32>

Source§

impl PacketField for f64

Source§

fn write_to(&self, buf: &mut Vec<u8>)

Source§

fn read_from(buf: &[u8], pos: &mut usize) -> Option<f64>

Source§

impl PacketField for i32

Source§

fn write_to(&self, buf: &mut Vec<u8>)

Source§

fn read_from(buf: &[u8], pos: &mut usize) -> Option<i32>

Source§

impl PacketField for i64

Source§

fn write_to(&self, buf: &mut Vec<u8>)

Source§

fn read_from(buf: &[u8], pos: &mut usize) -> Option<i64>

Source§

impl PacketField for u32

Source§

fn write_to(&self, buf: &mut Vec<u8>)

Source§

fn read_from(buf: &[u8], pos: &mut usize) -> Option<u32>

Source§

impl PacketField for u64

Source§

fn write_to(&self, buf: &mut Vec<u8>)

Source§

fn read_from(buf: &[u8], pos: &mut usize) -> Option<u64>

Implementors§