Document some encoding details

Also, update Cargo.toml with my name.
This commit is contained in:
Francesco Mazzoli 2015-01-07 03:49:19 +01:00
parent bfbaeaacd1
commit 0be3c68164
2 changed files with 18 additions and 1 deletions

View File

@ -1,7 +1,7 @@
[package]
name = "bincode"
version = "0.0.4"
authors = ["Ty Overby <ty@pre-alpha.com>"]
authors = ["Ty Overby <ty@pre-alpha.com>", "Francesco Mazzoli <f@mazzo.li>"]
repository = "https://github.com/TyOverby/bincode"
documentation = "http://tyoverby.github.io/bincode/bincode/"

View File

@ -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.