[][src]Crate cookie_factory

serialization library built with a combinator design similar to nom.

Serializers are built up from single purpose serializers, like slice to write a raw byte slice, or be_u16 to write a u16 integer in big endian form.

Those small serializers can then be assembled by using combinators. As an example, all(["abcd", "efgh", "ijkl"].iter().map(string))(output) will write "abcdefghijkl" to output.

Modules

lib

lib module necessary to reexport what we need from std in no_std mode

Macros

do_gen

Applies sub-generators in a sequence.

gen_align

gen_align!(I, u8) => I -> Result<I,E> Align the output buffer to the next multiple of specified value.

gen_at_offset

gen_at_offset!(usize, I -> Result<I,E>) => I -> Result<I,E> Combinator to call generator at an absolute offset.

gen_at_rel_offset

gen_at_offset!(usize, I -> Result<I,E>) => I -> Result<I,E> Combinator to call generator at a relative offset.

gen_be_f32

gen_be_f32!(I, f32) => I -> Result<I,E> Write a 4 byte float.

gen_be_f64

gen_be_f64!(I, f64) => I -> Result<I,E> Write a 8 byte float.

gen_be_i8

gen_be_i8!(I, i8) => I -> Result<I,E> Write a signed 1 byte integer.

gen_be_i16

gen_be_i16!(I, i16) => I -> Result<I,E> Write a signed 2 byte integer.

gen_be_i24

gen_be_i24!(I, i24) => I -> Result<I,E> Write a signed 3 byte integer.

gen_be_i32

gen_be_i32!(I, i32) => I -> Result<I,E> Write a signed 4 byte integer.

gen_be_i64

gen_be_i64!(I, i64) => I -> Result<I,E> Write a signed 8 byte integer.

gen_be_u8

gen_be_u8!(I, u8) => I -> Result<I,E> Write an unsigned 1 byte integer.

gen_be_u16

gen_be_u16!(I, u8) => I -> Result<I,E> Write an unsigned 2 bytes integer (using big-endian order).

gen_be_u24

gen_be_u24!(I, u8) => I -> Result<I,E> Write an unsigned 3 bytes integer (using big-endian order).

gen_be_u32

gen_be_u32!(I, u8) => I -> Result<I,E> Write an unsigned 4 bytes integer (using big-endian order).

gen_be_u64

gen_be_u64!(I, u8) => I -> Result<I,E> Write an unsigned 8 bytes integer (using big-endian order).

gen_call

Used to wrap common expressions and function as macros

gen_cond

gen_cond!(bool, I -> Result<I,E>) => I -> Result<I,E> Conditional combinator

gen_copy

gen_copy!(I, &[u8], u8) => I -> Result<I,E> Writes a slice, copying only the specified number of bytes to the output buffer.

gen_if_else

gen_if_else!(bool, I -> Result<I,E>, I -> Result<I,E>) => I -> Result<I,E> Conditional combinator, with alternate generator.

gen_le_f32

gen_le_f32!(I, f32) => I -> Result<I,E> Write a 4 byte float.

gen_le_f64

gen_le_f64!(I, f64) => I -> Result<I,E> Write a 8 byte float.

gen_le_i8

gen_le_i8!(I, i8) => I -> Result<I,E> Write a signed 1 byte integer.

gen_le_i16

gen_le_i16!(I, i16) => I -> Result<I,E> Write a signed 2 byte integer.

gen_le_i24

gen_le_i24!(I, i24) => I -> Result<I,E> Write a signed 3 byte integer.

gen_le_i32

gen_le_i32!(I, i32) => I -> Result<I,E> Write a signed 4 byte integer.

gen_le_i64

gen_le_i64!(I, i64) => I -> Result<I,E> Write a signed 8 byte integer.

gen_le_u8

gen_le_u8!(I, u8) => I -> Result<I,E> Write an unsigned 1 byte integer.

gen_le_u16

gen_le_u16!(I, u8) => I -> Result<I,E> Write an unsigned 2 bytes integer (using little-endian order).

gen_le_u24

gen_le_u24!(I, u8) => I -> Result<I,E> Write an unsigned 3 bytes integer (using little-endian order).

gen_le_u32

gen_le_u32!(I, u8) => I -> Result<I,E> Write an unsigned 4 bytes integer (using little-endian order).

gen_le_u64

gen_le_u64!(I, u8) => I -> Result<I,E> Write an unsigned 8 bytes integer (using little-endian order).

gen_length_slice
gen_many

gen_many!(I, Iterable<V>, Fn(I,V)) => I -> Result<I,E> Applies the generator $f to every element of $l, passing arguments by value.

gen_many_byref

gen_many_byref!(I, Iterable<V>, Fn(I,V)) => I -> Result<I,E> Applies the generator $f to every element of $l, where arguments of $l are references

gen_many_ref

gen_many_ref!(I, Iterable<V>, Fn(I,V)) => I -> Result<I,E> Applies the generator $f to every element of $l, passing arguments by reference.

gen_skip

gen_skip!(I, u8) => I -> Result<I,E> Skip the specified number of bytes.

gen_slice

gen_slice!(I, &[u8]) => I -> Result<I,E> Writes a slice, copying it entirely to the output buffer.

Structs

WriteCounter

Wrapper around Write that counts how much data was written

Enums

GenError

Base type for generator errors

Traits

SerializeFn

Trait for serializing functions

Skip

Trait for Write types that allow skipping over the data

Tuple

Helper trait for the tuple combinator

Functions

all

Applies an iterator of serializers of the same type

be_f32

Writes an f32 in big endian byte order to the output

be_f64

Writes an f64 in big endian byte order to the output

be_i8

Writes an i8 to the output

be_i16

Writes an i16 in big endian byte order to the output

be_i24

Writes the lower 24 bit of an i32 in big endian byte order to the output

be_i32

Writes an i32 in big endian byte order to the output

be_i64

Writes an i64 in big endian byte order to the output

be_u8

Writes an u8 to the output

be_u16

Writes an u16 in big endian byte order to the output

be_u24

Writes the lower 24 bit of an u32 in big endian byte order to the output

be_u32

Writes an u32 in big endian byte order to the output

be_u64

Writes an u64 in big endian byte order to the output

cond

Applies a serializer if the condition is true

hex

Writes an hex string to the output

le_f32

Writes an f32 in little endian byte order to the output

le_f64

Writes an f64 in little endian byte order to the output

le_i8

Writes an i8 to the output

le_i16

Writes an o16 in little endian byte order to the output

le_i24

Writes the lower 24 bit of an i32 in little endian byte order to the output

le_i32

Writes an i32 in little endian byte order to the output

le_i64

Writes an i64 in little endian byte order to the output

le_u8

Writes an u8 to the output

le_u16

Writes an u16 in little endian byte order to the output

le_u24

Writes the lower 24 bit of an u32 in little endian byte order to the output

le_u32

Writes an u32 in little endian byte order to the output

le_u64

Writes an u64 in little endian byte order to the output

legacy_wrap
many_ref

Applies a generator over an iterator of values, and applies the serializers generated

pair

Applies 2 serializers in sequence

separated_list

Applies an iterator of serializers of the same type with a separator between each serializer

set_be_u8

Write an unsigned 1 byte integer. Equivalent to gen_be_u8!(v)

set_be_u16

Write an unsigned 2 bytes integer (big-endian order). Equivalent to gen_be_u16!(v)

set_be_u32

Write an unsigned 4 bytes integer (big-endian order). Equivalent to gen_be_u32!(v)

set_be_u64

Write an unsigned 8 bytes integer (big-endian order). Equivalent to gen_be_u64!(v)

set_le_u8

Write an unsigned 1 byte integer. Equivalent to gen_le_u8!(v)

set_le_u16

Write an unsigned 2 bytes integer (little-endian order). Equivalent to gen_le_u16!(v)

set_le_u32

Write an unsigned 4 bytes integer (little-endian order). Equivalent to gen_le_u32!(v)

set_le_u64

Write an unsigned 8 bytes integer (little-endian order). Equivalent to gen_le_u64!(v)

skip

Skips over some input bytes without writing anything

slice

Writes a byte slice to the output

string

Writes a string slice to the output

tuple

Applies multiple serializers in sequence

Type Definitions

GenResult

Holds the result of serializing functions