rawcode
Welcome to rawcode
🎉
rawcode
is a no-std-compatible, simple as-is coding. The idea is similar to
bincode
, but the format is even more primitive: No variable length coding, no
references – just a few fixed-length types: bytes, booleans, integers, (nested) arrays/lists and StrArray
.
Types
There's built-in support for:
u8
: Bytes are encoded as-is (i.e. 8 bit, network bit order)bool
: Booleans are encoded asu8
wheretrue => 0xFF
andfalse => 0x00
i8
,u16
,i16
,u32
,i32
,u64
,i64
,u128
,i128
: Integers are encoded as two's-complement in little-endian representation and always use their full width (i.e.u16
= 2 bytes,i128
= 16 bytes)struct
s andarray
s: Fields are concatenated and encoded in order of declaration and without any padding inbetweenStrArray<LEN>
: This is a special wrapper around[u8; LEN]
which ensures that it's contents are always valid UTF-8
However please note that you can also easily implement the basic traits RawcodeConstSize
+ RawcodeEncode
+
RawcodeDecode
to provide encoding and derivation for your own types/wrappers.
Example
use ;
/// A named test struct
/// An unnamed test struct
;
// Create test struct and target buffer
let raw = Named ;
// Encode the named struct
let mut buf = ;
raw.encode.expect;
let decoded = decode.expect;
// Validate the decoding
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;