From 0be3c6816419de8f1da87eec2b2997135588563c Mon Sep 17 00:00:00 2001 From: Francesco Mazzoli Date: Wed, 7 Jan 2015 03:49:19 +0100 Subject: [PATCH] Document some encoding details Also, update Cargo.toml with my name. --- Cargo.toml | 2 +- README.md | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index be99929..fc15230 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bincode" version = "0.0.4" -authors = ["Ty Overby "] +authors = ["Ty Overby ", "Francesco Mazzoli "] repository = "https://github.com/TyOverby/bincode" documentation = "http://tyoverby.github.io/bincode/bincode/" diff --git a/README.md b/README.md index 4d446ae..26d547f 100644 --- a/README.md +++ b/README.md @@ -49,3 +49,20 @@ fn main() { } ``` + + +## Details + +The encoding (and thus decoding) proceeds unsurprisingly -- primitive +types are encoded according to the underlying `Writer`, tuples and +structs are encoded by encoding their fields one-by-one, and enums are +encoded by first writing out the tag representing the variant and +then the contents. + +However, there are some implementation details to be aware of: + +* `int`/`uint` are encoded as `i64`/`u64`, for portability. +* enums variants are encoded as a `u32` instead that as a `uint`. + `u32` is enough for all practical uses. +* `str` is encoded as `(u64, &[u8])`, where the `u64` is the number of + bytes contained in the encoded string.