pub struct PayloadReader<'a> { /* private fields */ }
Expand description

PayloadReader helps to read Bacho packet data.

Usage:

use bancho_packets::{PacketReader, PayloadReader};


let mut reader = PacketReader::new(&[
    4, 0, 0, 0, 0, 0, 0, 24, 0, 0, 19, 0, 0, 0, 11, 17, 72, 101, 108,
    108, 111, 44, 32, 87, 111, 114, 108, 100, 33, 240, 159, 146, 150,
    4, 0, 0, 0, 0, 0, 0, 24, 0, 0, 18, 0, 0, 0, 11, 16, 229, 147, 136,
    229, 147, 136, 227, 128, 144, 240, 159, 152, 131, 227, 128, 145,
    104, 0, 0, 0, 0, 0, 0, 24, 0, 0, 23, 0, 0, 0, 11, 21, 232, 175,
    187, 229, 143, 150, 229, 174, 140, 228, 186, 134, 239, 188, 129,
    239, 188, 129, 226, 156, 168,
]);
while let Some(packet) = reader.next() {
    print!("packet id: {:?}: ", packet.id);
    match packet.payload {
        None => println!("Non-payload"),
        Some(payload) => {
            let mut payload_reader = PayloadReader::new(payload);
            println!("payload as string: {:?}", payload_reader.read::<String>());
        },
    }
}

Implementations§

Try to read <T> from payloads. Returns None when no data matching the given type can be read.

Reset read progress to 0.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.