muscleman

muscleman is a library for creating and managing buffers. It gets its name from the fact that it is a buffer manager. And thinking of "buff" as in "buff body", it is a library for managing buffers of data. Plus, muscle man is a funny character.

Usage

Add this to your Cargo.toml: toml [dependencies] muscleman = "0.3.1" And this to your crate root: rust extern crate muscleman; use muscleman::buffer::Buffer;

Examples

Creating a buffer

```rust use muscleman::buffer;

let mut buffer = buffer::new(); buffer.writebyte(0x01); buffer.writebyte(0x02);

assert_eq!(buffer.len(), 2); ```

Writing to a buffer

```rust use muscleman::buffer;

let mut buffer = buffer::new();

// 8 to 64 bit signed integers buffer.writei8(1); buffer.writei16(2); buffer.writei32(3); buffer.writei64(4);

// 8 to 64 bit unsigned integers buffer.writeu8(5); buffer.writeu16(6); buffer.writeu32(7); buffer.writeu64(8);

// 32 and 64 bit floating point numbers buffer.writef32(9.0f32); buffer.writef64(10.0f64);

// Null terminated strings and length prefixed strings buffer.writestring("Hello, world!"); buffer.writestringwithlength("Hello, world!"); // The length is written as a u32 ```

Reading from a buffer

```rust use muscleman::buffer;

let mut buffer = buffer::new();

// Assume the data in the "Writing to a buffer" is currently in the buffer

// 8 to 64 bit signed integers asserteq!(buffer.readi8(), 1); asserteq!(buffer.readi16(), 2); asserteq!(buffer.readi32(), 3); asserteq!(buffer.readi64(), 4);

// 8 to 64 bit unsigned integers asserteq!(buffer.readu8(), 5); asserteq!(buffer.readu16(), 6); asserteq!(buffer.readu32(), 7); asserteq!(buffer.readu64(), 8);

// 32 and 64 bit floating point numbers asserteq!(buffer.readf32(), 9.0f32); asserteq!(buffer.readf64(), 10.0f64);

// Null terminated strings and length prefixed strings asserteq!(buffer.readstring(), "Hello, world!"); asserteq!(buffer.readstringwithlength(), "Hello, world!"); ```

Why?

I was working on a project that required me to send and receive data from a server. I needed a way to easily write and read data to and from a buffer. I looked around and found a few crates that did this, but they were either too complicated or didn't do what I needed. So I decided to make my own.

License

muscleman is licensed under the MIT license. See the LICENSE file for more information.