Skip to content

Commit

Permalink
Update spec for Option<T> encoding (#702)
Browse files Browse the repository at this point in the history
* Update spec for Option<T> encoding

* Fix header rank
  • Loading branch information
mkeeter committed Mar 17, 2024
1 parent 9255d49 commit b5fbbf9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ assert_eq!(encoded.as_slice(), &[
]);
```

### Options
`Option<T>` is always serialized using a single byte for the discriminant, even in `Fixint` encoding (which normally uses a `u32` for discriminant).

```rust
let data: Option<u32> = Some(123);
let encoded = bincode::encode_to_vec(data, bincode::config::legacy()).unwrap();
assert_eq!(encoded.as_slice(), &[
1, 123, 0, 0, 0 // the Some(..) tag is the leading 1
]);

let data: Option<u32> = None;
let encoded = bincode::encode_to_vec(data, bincode::config::legacy()).unwrap();
assert_eq!(encoded.as_slice(), &[
0 // the None tag is simply 0
]);
```

# Collections

Collections are encoded with their length value first, following by each entry of the collection. The length value is based on your `IntEncoding`.
Expand Down

0 comments on commit b5fbbf9

Please sign in to comment.