Skip to main content

Crate pkbuffer

Crate pkbuffer 

Source
Expand description

PKBuffer is a library for reading and writing data to byte buffers using safe byte-copy operations. It creates an interface for reading and writing primitive types and byte sequences to an arbitrary buffer of bytes.

For example:

use pkbuffer::{Buffer, VecBuffer};

let mut buffer = VecBuffer::with_initial_size(4);
buffer.write_val::<u32>(0, &0x07060504).unwrap();

assert_eq!(buffer, [4,5,6,7]);

Buffer objects are derived from the Buffer trait. This trait provides methods for reading, writing, searching, and manipulating byte buffers.

Buffer objects comes in two forms: pointer form (PtrBuffer) and allocated form (VecBuffer). Each of these structures come in handy for different reasons. PtrBuffer is useful on unowned data such as arbitrary locations in memory, whereas VecBuffer’s utility comes from being able to manipulate the underlying owned data.

VecBuffers are handy for creating a brand-new buffer of objects.

use pkbuffer::{Buffer, VecBuffer};

let mut buffer = VecBuffer::new();
buffer.append_val::<u8>(&0x1);
buffer.append_val::<u16>(&0x0302);
buffer.append_val::<u32>(&0x07060504);
assert_eq!(buffer, [1,2,3,4,5,6,7]);

§Safety

All type reads and writes use safe byte-copy operations via read_val<T> and write_val<T>, which work correctly regardless of alignment on all platforms. No unsafe pointer casting is used.

Structs§

BufferIter
An iterator for a Buffer object.
BufferIterMut
A mutable iterator for a Buffer object.
BufferSearchDynamicIter
An iterator for searching over a Buffer’s space for a given dynamic search term.
BufferSearchIter
An iterator for searching over a Buffer’s space for a given binary search term.
PtrBuffer
A Buffer object backed by a pointer/size pair. Use this buffer type when accessing unowned memory or arbitrary allocated memory.
VecBuffer
An owned-data Buffer object.

Enums§

Error
Errors produced by the library.

Traits§

Buffer
The trait by which all buffer objects are derived.