[][src]Crate pigeon

A crate for reading/writing from/to byte buffers.

This crate uses big-endian for all numbers.

Usage Example

use {
    pigeon::{
        Writer,
        Reader,
        Target,
        Unpack,
        Pack,
        ShortStr,
        WriteResult,
        ReadResult,
    },
};

pub struct Animal {
    pub position: (f32, f32, f32),
    pub fluffy: bool,
    pub name: String,
    pub weight: f32,
}

impl Pack for Animal {
    fn pack<T: Target>(&self, writer: &mut Writer<T>) -> WriteResult<()> {
        writer.write(self.position)?;
        writer.write(self.fluffy)?;
        writer.write(ShortStr(&self.name))?;
        writer.write(self.weight)?;
        Ok(())
    }
}

impl<'a> Unpack<'a> for Animal {
    fn unpack(reader: &mut Reader<'a>) -> ReadResult<Self> {
        let position = reader.read()?;
        let fluffy = reader.read()?;
        let ShortStr(name) = reader.read()?;
        let weight = reader.read()?;
        Ok(Animal {
            position,
            fluffy,
            name: name.to_owned(),
            weight,
        })
    }
}

Structs

Reader

A type that can be used to read from a buffer.

ShortStr

A UTF-8 string that is prefixed with its length, where the length field is a u8.

Writer

A type which can be used for writing to a type that implements Target.

Enums

ReadError

An error which can be emitted when a read fails.

WriteError

An error which can be emitted when a write fails.

Traits

Pack

Types which can get written to a Writer.

Target

A type which can be written to by a Writer.

Unpack

Types which can get read from a Reader.

Functions

pack_buffer

Pack the type to a buffer directly.

unpack_buffer

Read a type which implement Unpack from the buffer.

Type Definitions

ReadResult

A type alias for a Result that returns an Error.

WriteResult

A type alias for a Result that returns an Error.