Struct t2plugin::slread::SliceReader [] [src]

pub struct SliceReader<'a> { /* fields omitted */ }

Tool to decode protocols from a byte slice.

The slice can be consumed as different types of integers (u16, u32, ...) for binary protocols or read line by line for text protocols.

All numbers read from the slice are assumed to be stored in big endian (network order).

Methods

impl<'a> SliceReader<'a>
[src]

Creates a new SliceReader from a slice of u8.

Reads and consumes a u8 from the slice.

Reads and consumes a u16 from the slice.

Reads and consumes a u24 from the slice.

u24 is actually a u32 but only consumes 3 bytes from the slice.

Reads and consumes a u32 from the slice.

Example

use t2plugin::slread::SliceReader;
use t2plugin::nethdr::Packet;
 
...
let slr = SliceReader::new(packet.l7_header());
// read the first 32 bits of the packet payload
let id = try!(slr.read_u32());

Reads and consumes a u48 from the slice.

u48 is actually a u64 but only consumes 6 bytes from the slice.

Reads and consumes a u64 from the slice.

Copies and consumes a sub-slice to a mutable buffer.

Example

use t2plugin::slread::SliceReader;
use t2plugin::nethdr::Packet;
 
...
let slr = SliceReader::new(packet.l7_header());
let mut data = [0u8; 6];
try!(slr.read_copy(&mut data));

Returns and consumes a sub-slice containing count bytes.

The lifetime of the returned slice is the same as the one of the slice provided when creating this SliceReader with the new method.

Reads buffer until the first occurence of byte.

The lifetime of the returned slice is the same as the one of the slice provided when creating this SliceReader with the new method.

Reads a line from the buffer.

The line is returned as a slice of byte. This is necessary in order to also process lines which contain invalid UTF-8 characters.

The lifetime of the returned line is the same as the one of the slice provided when creating this SliceReader with the new method.

Example

use t2plugin::slread::{SliceReader, TrimBytes};
use t2plugin::nethdr::Packet;

let slr = SliceReader::new(packet.l7_header());
// read the packet payload line by line
while let Ok(line) = slr.read_line() {
    if line.starts_with(b"User-Agent: ") {
        let ua = line[12 ..].trim();
        // do something with HTTP user agent
    }
}

Skips count bytes of the slice.

Seeks back count bytes in the slice.

Return the number of bytes left in the slice.

Returns the current position in the buffer.

Shortens the slice by count bytes.

On success, returns the slice new length.

Trait Implementations

impl<'a> Seek for SliceReader<'a>
[src]

Seek to an offset, in bytes, in a stream. Read more