Trait webparse::binary::Buf

source ·
pub trait Buf {
Show 53 methods // Required methods fn remaining(&self) -> usize; fn chunk(&self) -> &[u8] ; fn advance(&mut self, n: usize); fn mark_slice_skip(&mut self, skip: usize) -> &[u8] ; fn mark_commit(&mut self) -> usize; fn mark_len(&mut self, len: usize); fn mark_clone_slice_range<R: RangeBounds<isize>>(&self, range: R) -> Self where Self: Sized; // Provided methods fn mark_clone_slice(&self) -> Self where Self: Sized { ... } fn mark_slice(&mut self) -> &[u8] { ... } fn mark_bump(&mut self) { ... } fn advance_all(&mut self) { ... } fn peek(&self) -> Option<u8> { ... } fn has_remaining(&self) -> bool { ... } fn get_next(&mut self) -> Option<u8> { ... } fn copy_to_slice(&mut self, dst: &mut [u8]) -> usize { ... } fn get_u8(&mut self) -> u8 { ... } fn get_i8(&mut self) -> i8 { ... } fn get_u16(&mut self) -> u16 { ... } fn get_u16_le(&mut self) -> u16 { ... } fn get_u16_ne(&mut self) -> u16 { ... } fn get_i16(&mut self) -> i16 { ... } fn get_i16_le(&mut self) -> i16 { ... } fn get_i16_ne(&mut self) -> i16 { ... } fn get_u32(&mut self) -> u32 { ... } fn get_u32_le(&mut self) -> u32 { ... } fn get_u32_ne(&mut self) -> u32 { ... } fn get_i32(&mut self) -> i32 { ... } fn get_i32_le(&mut self) -> i32 { ... } fn get_i32_ne(&mut self) -> i32 { ... } fn get_u64(&mut self) -> u64 { ... } fn get_u64_le(&mut self) -> u64 { ... } fn get_u64_ne(&mut self) -> u64 { ... } fn get_i64(&mut self) -> i64 { ... } fn get_i64_le(&mut self) -> i64 { ... } fn get_i64_ne(&mut self) -> i64 { ... } fn get_u128(&mut self) -> u128 { ... } fn get_u128_le(&mut self) -> u128 { ... } fn get_u128_ne(&mut self) -> u128 { ... } fn get_i128(&mut self) -> i128 { ... } fn get_i128_le(&mut self) -> i128 { ... } fn get_i128_ne(&mut self) -> i128 { ... } fn get_uint(&mut self, nbytes: usize) -> u64 { ... } fn get_uint_le(&mut self, nbytes: usize) -> u64 { ... } fn get_uint_ne(&mut self, nbytes: usize) -> u64 { ... } fn get_int(&mut self, nbytes: usize) -> i64 { ... } fn get_int_le(&mut self, nbytes: usize) -> i64 { ... } fn get_int_ne(&mut self, nbytes: usize) -> i64 { ... } fn get_f32(&mut self) -> f32 { ... } fn get_f32_le(&mut self) -> f32 { ... } fn get_f32_ne(&mut self) -> f32 { ... } fn get_f64(&mut self) -> f64 { ... } fn get_f64_le(&mut self) -> f64 { ... } fn get_f64_ne(&mut self) -> f64 { ... }
}

Required Methods§

source

fn remaining(&self) -> usize

获取剩余数量

source

fn chunk(&self) -> &[u8]

获取当前数据的切片引用

source

fn advance(&mut self, n: usize)

消耗掉多少字节的数据, 做指针偏移

source

fn mark_slice_skip(&mut self, skip: usize) -> &[u8]

获取从起始值到当前值的slice引用

source

fn mark_commit(&mut self) -> usize

把当前值赋值给起始值

source

fn mark_len(&mut self, len: usize)

更改数据大小

source

fn mark_clone_slice_range<R: RangeBounds<isize>>(&self, range: R) -> Selfwhere Self: Sized,

克隆当前的对象, 并限定范围

Provided Methods§

source

fn mark_clone_slice(&self) -> Selfwhere Self: Sized,

克隆当前的对象, 取当前余下的

source

fn mark_slice(&mut self) -> &[u8]

source

fn mark_bump(&mut self)

source

fn advance_all(&mut self)

消耗所有的字节

source

fn peek(&self) -> Option<u8>

获取当前的值, 但不做任何偏移

source

fn has_remaining(&self) -> bool

是否还有数据

source

fn get_next(&mut self) -> Option<u8>

获取当前的值并将偏移值+1

source

fn copy_to_slice(&mut self, dst: &mut [u8]) -> usize

拷贝数据 self into dst.

Examples
use webparse::binary;
use binary::Buf;

let mut buf = &b"hello world"[..];
let mut dst = [0; 5];

buf.copy_to_slice(&mut dst);
assert_eq!(&b"hello"[..], &dst);
assert_eq!(6, buf.remaining());
Panics

This function panics if self.remaining() < dst.len()

source

fn get_u8(&mut self) -> u8

source

fn get_i8(&mut self) -> i8

source

fn get_u16(&mut self) -> u16

Gets an unsigned 16 bit integer from self in big-endian byte order.

The current position is advanced by 2.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x08\x09 hello"[..];
assert_eq!(0x0809, buf.get_u16());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u16_le(&mut self) -> u16

Gets an unsigned 16 bit integer from self in little-endian byte order.

The current position is advanced by 2.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x09\x08 hello"[..];
assert_eq!(0x0809, buf.get_u16_le());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u16_ne(&mut self) -> u16

Gets an unsigned 16 bit integer from self in native-endian byte order.

The current position is advanced by 2.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x08\x09 hello",
    false => b"\x09\x08 hello",
};
assert_eq!(0x0809, buf.get_u16_ne());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i16(&mut self) -> i16

Gets a signed 16 bit integer from self in big-endian byte order.

The current position is advanced by 2.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x08\x09 hello"[..];
assert_eq!(0x0809, buf.get_i16());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i16_le(&mut self) -> i16

Gets a signed 16 bit integer from self in little-endian byte order.

The current position is advanced by 2.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x09\x08 hello"[..];
assert_eq!(0x0809, buf.get_i16_le());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i16_ne(&mut self) -> i16

Gets a signed 16 bit integer from self in native-endian byte order.

The current position is advanced by 2.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x08\x09 hello",
    false => b"\x09\x08 hello",
};
assert_eq!(0x0809, buf.get_i16_ne());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u32(&mut self) -> u32

Gets an unsigned 32 bit integer from self in the big-endian byte order.

The current position is advanced by 4.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x08\x09\xA0\xA1 hello"[..];
assert_eq!(0x0809A0A1, buf.get_u32());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u32_le(&mut self) -> u32

Gets an unsigned 32 bit integer from self in the little-endian byte order.

The current position is advanced by 4.

Examples
use webparse::binary::Buf;

let mut buf = &b"\xA1\xA0\x09\x08 hello"[..];
assert_eq!(0x0809A0A1, buf.get_u32_le());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u32_ne(&mut self) -> u32

Gets an unsigned 32 bit integer from self in native-endian byte order.

The current position is advanced by 4.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x08\x09\xA0\xA1 hello",
    false => b"\xA1\xA0\x09\x08 hello",
};
assert_eq!(0x0809A0A1, buf.get_u32_ne());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i32(&mut self) -> i32

Gets a signed 32 bit integer from self in big-endian byte order.

The current position is advanced by 4.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x08\x09\xA0\xA1 hello"[..];
assert_eq!(0x0809A0A1, buf.get_i32());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i32_le(&mut self) -> i32

Gets a signed 32 bit integer from self in little-endian byte order.

The current position is advanced by 4.

Examples
use webparse::binary::Buf;

let mut buf = &b"\xA1\xA0\x09\x08 hello"[..];
assert_eq!(0x0809A0A1, buf.get_i32_le());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i32_ne(&mut self) -> i32

Gets a signed 32 bit integer from self in native-endian byte order.

The current position is advanced by 4.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x08\x09\xA0\xA1 hello",
    false => b"\xA1\xA0\x09\x08 hello",
};
assert_eq!(0x0809A0A1, buf.get_i32_ne());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u64(&mut self) -> u64

Gets an unsigned 64 bit integer from self in big-endian byte order.

The current position is advanced by 8.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x01\x02\x03\x04\x05\x06\x07\x08 hello"[..];
assert_eq!(0x0102030405060708, buf.get_u64());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u64_le(&mut self) -> u64

Gets an unsigned 64 bit integer from self in little-endian byte order.

The current position is advanced by 8.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x08\x07\x06\x05\x04\x03\x02\x01 hello"[..];
assert_eq!(0x0102030405060708, buf.get_u64_le());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u64_ne(&mut self) -> u64

Gets an unsigned 64 bit integer from self in native-endian byte order.

The current position is advanced by 8.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x01\x02\x03\x04\x05\x06\x07\x08 hello",
    false => b"\x08\x07\x06\x05\x04\x03\x02\x01 hello",
};
assert_eq!(0x0102030405060708, buf.get_u64_ne());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i64(&mut self) -> i64

Gets a signed 64 bit integer from self in big-endian byte order.

The current position is advanced by 8.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x01\x02\x03\x04\x05\x06\x07\x08 hello"[..];
assert_eq!(0x0102030405060708, buf.get_i64());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i64_le(&mut self) -> i64

Gets a signed 64 bit integer from self in little-endian byte order.

The current position is advanced by 8.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x08\x07\x06\x05\x04\x03\x02\x01 hello"[..];
assert_eq!(0x0102030405060708, buf.get_i64_le());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i64_ne(&mut self) -> i64

Gets a signed 64 bit integer from self in native-endian byte order.

The current position is advanced by 8.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x01\x02\x03\x04\x05\x06\x07\x08 hello",
    false => b"\x08\x07\x06\x05\x04\x03\x02\x01 hello",
};
assert_eq!(0x0102030405060708, buf.get_i64_ne());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u128(&mut self) -> u128

Gets an unsigned 128 bit integer from self in big-endian byte order.

The current position is advanced by 16.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16 hello"[..];
assert_eq!(0x01020304050607080910111213141516, buf.get_u128());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u128_le(&mut self) -> u128

Gets an unsigned 128 bit integer from self in little-endian byte order.

The current position is advanced by 16.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01 hello"[..];
assert_eq!(0x01020304050607080910111213141516, buf.get_u128_le());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_u128_ne(&mut self) -> u128

Gets an unsigned 128 bit integer from self in native-endian byte order.

The current position is advanced by 16.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16 hello",
    false => b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01 hello",
};
assert_eq!(0x01020304050607080910111213141516, buf.get_u128_ne());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i128(&mut self) -> i128

Gets a signed 128 bit integer from self in big-endian byte order.

The current position is advanced by 16.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16 hello"[..];
assert_eq!(0x01020304050607080910111213141516, buf.get_i128());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i128_le(&mut self) -> i128

Gets a signed 128 bit integer from self in little-endian byte order.

The current position is advanced by 16.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01 hello"[..];
assert_eq!(0x01020304050607080910111213141516, buf.get_i128_le());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_i128_ne(&mut self) -> i128

Gets a signed 128 bit integer from self in native-endian byte order.

The current position is advanced by 16.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16 hello",
    false => b"\x16\x15\x14\x13\x12\x11\x10\x09\x08\x07\x06\x05\x04\x03\x02\x01 hello",
};
assert_eq!(0x01020304050607080910111213141516, buf.get_i128_ne());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_uint(&mut self, nbytes: usize) -> u64

Gets an unsigned n-byte integer from self in big-endian byte order.

The current position is advanced by nbytes.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x01\x02\x03 hello"[..];
assert_eq!(0x010203, buf.get_uint(3));
Panics

This function panics if there is not enough remaining data in self.

source

fn get_uint_le(&mut self, nbytes: usize) -> u64

Gets an unsigned n-byte integer from self in little-endian byte order.

The current position is advanced by nbytes.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x03\x02\x01 hello"[..];
assert_eq!(0x010203, buf.get_uint_le(3));
Panics

This function panics if there is not enough remaining data in self.

source

fn get_uint_ne(&mut self, nbytes: usize) -> u64

Gets an unsigned n-byte integer from self in native-endian byte order.

The current position is advanced by nbytes.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x01\x02\x03 hello",
    false => b"\x03\x02\x01 hello",
};
assert_eq!(0x010203, buf.get_uint_ne(3));
Panics

This function panics if there is not enough remaining data in self.

source

fn get_int(&mut self, nbytes: usize) -> i64

Gets a signed n-byte integer from self in big-endian byte order.

The current position is advanced by nbytes.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x01\x02\x03 hello"[..];
assert_eq!(0x010203, buf.get_int(3));
Panics

This function panics if there is not enough remaining data in self.

source

fn get_int_le(&mut self, nbytes: usize) -> i64

Gets a signed n-byte integer from self in little-endian byte order.

The current position is advanced by nbytes.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x03\x02\x01 hello"[..];
assert_eq!(0x010203, buf.get_int_le(3));
Panics

This function panics if there is not enough remaining data in self.

source

fn get_int_ne(&mut self, nbytes: usize) -> i64

Gets a signed n-byte integer from self in native-endian byte order.

The current position is advanced by nbytes.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x01\x02\x03 hello",
    false => b"\x03\x02\x01 hello",
};
assert_eq!(0x010203, buf.get_int_ne(3));
Panics

This function panics if there is not enough remaining data in self.

source

fn get_f32(&mut self) -> f32

Gets an IEEE754 single-precision (4 bytes) floating point number from self in big-endian byte order.

The current position is advanced by 4.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x3F\x99\x99\x9A hello"[..];
assert_eq!(1.2f32, buf.get_f32());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_f32_le(&mut self) -> f32

Gets an IEEE754 single-precision (4 bytes) floating point number from self in little-endian byte order.

The current position is advanced by 4.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x9A\x99\x99\x3F hello"[..];
assert_eq!(1.2f32, buf.get_f32_le());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_f32_ne(&mut self) -> f32

Gets an IEEE754 single-precision (4 bytes) floating point number from self in native-endian byte order.

The current position is advanced by 4.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x3F\x99\x99\x9A hello",
    false => b"\x9A\x99\x99\x3F hello",
};
assert_eq!(1.2f32, buf.get_f32_ne());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_f64(&mut self) -> f64

Gets an IEEE754 double-precision (8 bytes) floating point number from self in big-endian byte order.

The current position is advanced by 8.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x3F\xF3\x33\x33\x33\x33\x33\x33 hello"[..];
assert_eq!(1.2f64, buf.get_f64());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_f64_le(&mut self) -> f64

Gets an IEEE754 double-precision (8 bytes) floating point number from self in little-endian byte order.

The current position is advanced by 8.

Examples
use webparse::binary::Buf;

let mut buf = &b"\x33\x33\x33\x33\x33\x33\xF3\x3F hello"[..];
assert_eq!(1.2f64, buf.get_f64_le());
Panics

This function panics if there is not enough remaining data in self.

source

fn get_f64_ne(&mut self) -> f64

Gets an IEEE754 double-precision (8 bytes) floating point number from self in native-endian byte order.

The current position is advanced by 8.

Examples
use webparse::binary::Buf;

let mut buf: &[u8] = match cfg!(target_endian = "big") {
    true => b"\x3F\xF3\x33\x33\x33\x33\x33\x33 hello",
    false => b"\x33\x33\x33\x33\x33\x33\xF3\x3F hello",
};
assert_eq!(1.2f64, buf.get_f64_ne());
Panics

This function panics if there is not enough remaining data in self.

Implementors§

source§

impl Buf for Binary

source§

impl Buf for BinaryMut

source§

impl<'a> Buf for BinaryRef<'a>