* Add benchmarks for varint parsing
* Enable more inlining
* Outline error construction
* Add provided functions to BincodeRead to customize reading of literals
* Add #[inline] to deserialize_byte
* Outline SliceReader::unexpected_eof so that deserialize_varint inlines
* Implement BincodeRead for std::io::BufReader
* Reimplement all of BincodeRead in terms of BufRead-like functions
* Move branch into error-creation function to get below inline threshold
* Address questions regarding suitability for storage and untrusted inputs
Puts some prominent text into the `readme.md` regarding some use cases
that are likely to be common, along with a few hopefully helpful
pointers to avoid footguns.
Closes#345, closes#216, addresses #240, #266.
* Fix typos in `readme.md`
* Remove confusing sentence post 1.0, as requested
Due to historical reasons, the default options used by bincode for the
helper functions at the root of the crate differ from the options in
the `config` module.
Changing the default options is a breaking change, so until a decision
is made, we can at least document the current behavior.
Having these in the impl block with a generic R paramter would make
them unusable, at least without type annotations:
error[E0282]: type annotations needed
--> msg_socket2/src/socket.rs:45:32
|
45 | let mut deserializer = Deserializer::with_reader(bytes.as_slice(), DefaultOptions::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `R`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.
Moving these into separate impl blocks, which set the type of the
Deserializer to the return type of the functions, fixes this error.
Break up the config module into one submodule per configuration
option. This commit also changes the default configuration with
the new options system to be varint (the old system still uses
fixint to preserve backwards compatibility).
Adds varint encoding to all numbers, including sequence lengths and enum discriminants. Varints are encoded according to the following scheme
1. If `u < 251`, encode it as a single byte with that value.
2. If `251 <= u < 2**16`, encode it as a literal byte 251, followed by a u16 with value `u`.
3. If `2**16 <= u < 2**32`, encode it as a literal byte 252, followed by a u32 with value `u`.
4. If `2**32 <= u < 2**64`, encode it as a literal byte 253, followed by a u64 with value `u`.
5. If `2**64 <= u < 2**128`, encode it as a literal byte 254, followed by a u128 with value `u`.
Signed integers are first encoded using zigzag format (see docs for details)
Co-authored-by: Maciej Hirsz <maciej.hirsz@gmail.com>
Co-authored-by: Nicole Mazzuca <nicole@strega-nil.co>
Deprecate the old config system and make a refined version of the internal config system public. Doing allows the Serializer/Deserializer to be exposed since all of its generic type parameters are now public.
The default read implementation on slices was not generating efficient code. This custom implementation generates much smaller assembly with fewer function calls.