Commit Graph

144 Commits

Author SHA1 Message Date
Trangar 7cb10d4ab3 Added test case for a borrowed str (#441) 2021-12-02 11:44:08 +01:00
Trangar 4be23b88de Added Decode/Encode for HashMap<K, V> (#438) 2021-11-22 15:18:58 +01:00
Trangar ad7ddebff3 Allow serde types to be Decode/Encoded (#434)
* Added support for #[bincode(serde)] attribute on fields, added SerdeToBincode helper struct

* Switch to using Compat/BorrowCompat

* Moved all the serde features and functions to its own module

* Fix broken link

* Added support for the bincode(with_serde) attribute in enum variants

* Updated the main documentation on serde, fixed an example not compiling under certain feature flag combinations

* Added #[serde(flatten)] to the list of problematic attributes

* Added better error reporting on invalid attributes
2021-11-09 10:08:47 +01:00
Trangar 8c1279feab functions to enable encoding/decoding serde types (#422)
* functions to enable encoding/decoding serde types
* Removed dev feature I forgot to remove
* Centralized option variant and len() decoding/encoding
2021-11-08 12:38:29 +01:00
Trangar cc13be30d4 split off BorrowDecode from Decode in bincode_derive (#432)
* split off BorrowDecode from Decode in bincode_derive

* Added test case for issue #431

* Fixed Cow implementation having the wrong constraint, added BlockedTODO for cow implementation specialization

* Re-exported the Decode and Encode traits in the crate root

* Removed outdated comments

* Removed some :🇩🇪:Decode that were introduced by the merge
2021-11-07 10:57:35 +01:00
Trangar b4c46a789a Fixes for 427 (#428)
* Made bincode_derive handle empty lines of docs correctly
* Made bincode_derive properly support const generics
* Added support for enums with variants with fixed values
2021-11-07 10:31:15 +01:00
Lena Hellström 99de47a6c8 Reintroduce varint optimizations 2021-10-24 16:44:36 +02:00
Victor Koenders 707d0d238f Made all encode and decode functions always require a Config, removed _with_config functions 2021-10-21 14:19:40 +02:00
Victor Koenders 151edf46d3 Included spec.md into cargo's documentation, fixed the issues, changed the [u8; N] implementations to [T; N] 2021-10-21 11:57:16 +02:00
Lena Hellström 684f2562b1 Config rewrite (#412)
Rewrite the config system to be slightly more friendly to adding new options
2021-10-17 21:07:31 +02:00
Victor Koenders 02a9b2cb71 Made the test stage throw an error on warnings 2021-10-17 17:23:28 +02:00
Lena Hellström e232454936 Refactor and rename encoders 2021-10-17 16:22:14 +02:00
Victor Koenders 61c1e8a7cd Added badges to the functions to indicate which features they require 2021-10-17 15:00:14 +02:00
Victor Koenders 1f261cede3 Added support for atomic integers 2021-10-16 14:49:18 +02:00
Victor Koenders 8ab730eb87 Added support for IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6 2021-10-16 14:28:06 +02:00
Victor Koenders a0469e08ef Added support for NonZero* types 2021-10-16 14:14:15 +02:00
Victor Koenders 9420d03762 Added support for Range<T>, RangeInclusive<T> and Bound<T> 2021-10-16 13:59:48 +02:00
Victor Koenders 26d7683719 Added support for Path and PathBuf 2021-10-16 13:47:48 +02:00
Victor Koenders acbd385649 Added core::time::Duration and std::time::SystemTime 2021-10-16 13:32:12 +02:00
Victor Koenders 9cf577d9bc Added support for String, Mutex<T> and RwLock<T> 2021-10-16 13:19:30 +02:00
Victor Koenders 33dd4f761d Added support for CStr and CString 2021-10-16 12:59:38 +02:00
Victor Koenders a322e0f1b3 Added support for BinaryHeap, BTreeMap, BTreeSet and VecDeque 2021-10-16 12:21:52 +02:00
Victor Koenders 4e1a72796c Added support for Cow, Rc and Arc 2021-10-16 12:08:29 +02:00
Victor Koenders 1d6379e715 Added support for Cell and RefCell 2021-10-16 12:04:23 +02:00
Victor Koenders 07f49e878e Added support for Vec<T>, Box<T> and Box<[T]> 2021-10-16 11:41:59 +02:00
Victor Koenders 82924aa96e Added support for Option<T> and Result<T, U> 2021-10-16 11:03:25 +02:00
Victor Koenders 960b6066cd Added an option to encode a fixed array length or to skip it 2021-10-14 21:31:47 +02:00
Victor Koenders 19fed15463 Added support for tuples with up to 8 values 2021-10-14 20:33:03 +02:00
Victor Koenders e4e12c984b Added support for the bool type 2021-10-14 19:34:35 +02:00
Victor Koenders c4cb220fb2 Added support for char encoding/decoding 2021-10-14 19:28:28 +02:00
Victor Koenders c969622384 Added alloc and std tests 2021-10-12 16:13:21 +02:00
Trangar a27b63b7fa Make bincode_derive 0 dependencies (#409)
Removed `syn`, `quote` and `proc_macro2` dependency
2021-10-12 15:53:02 +02:00
Victor Koenders 8e99d580b8 Removed `allow` attributes, fixed some warnings 2021-09-26 09:19:39 +02:00
Lena Hellström 044942891f Clean up the borrow crimes 2021-09-22 22:17:26 +02:00
Victor Koenders 254b87c6eb Moved all feature flags to src/features, made the CI run tests on all feature combinations 2021-09-22 16:23:27 +02:00
Victor Koenders 9c7fb85e0e Added support for slices, str, fixed size arrays. Added lifetime to Decode trait 2021-09-22 12:03:00 +02:00
Victor Koenders ffb565c405 Added config options for endian and int_encoding, added full coverage for all basic integer types 2021-09-22 10:40:27 +02:00
Lena Hellström c83c36333d Add enum encode/decode derive 2021-09-20 23:06:25 +02:00
Lena Hellström 2d0254405b Add derive support for tuple structs 2021-09-20 16:56:17 +02:00
Lena Hellström e414cabd33 Add derive for Decodeable 2021-09-20 16:35:36 +02:00
Lena Hellström 8241e6c656 Add generic bound support to derive 2021-09-20 16:27:13 +02:00
Victor Koenders 723bdd312a Turned Config::INT_ENCODING back into a const, made a ton of varint_encode functions 2021-09-19 09:25:47 +02:00
Victor Koenders bab0cf4bd1 Started working on bincode_derive 2021-09-13 13:20:47 +02:00
Lena Hellström b7c0d1fac0 reorganize de/enc modules 2021-06-20 00:12:10 +02:00
Lena Hellström e160c73acb a fresh new start 2021-06-19 19:31:34 +02:00
Lena Hellström e39a047b4b prep branch for 2.0 work (#379)
* prep branch for 2.0 work

* switch to 2018 edition

* fix clippy issues

* fix tests

* fix warnings

* fix formatting
2021-04-08 14:54:31 +02:00
Lena Hellström 00c43bf3b1 fix logic error in fill_buffer (#336) 2020-06-23 23:41:55 -07:00
Lena Hellström e80f61b9da Reject trailing bytes (#198) 2020-05-26 12:40:04 -07:00
Lena Hellström f9faa33686 refactor config module (#323)
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).
2020-05-18 22:46:12 -07:00
Lena Hellström c27e9c6874 Varint enum tags and lengths (#306)
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>
2020-05-18 17:07:10 -07:00
Lena Hellström 2355e48a7b expose default options and serializers (#310)
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.
2020-04-16 15:23:07 -07:00
Lena Hellström 8839b0600d Modernize CI (#311)
Switches our CI from Travis-CI to Github Actions. At the same time this also turns on clippy and rustfmt linting.
2020-03-24 14:33:13 -07:00
Justin Starry 0215da2d29 Fix emscripten build failures due to lack of i128 support 2019-10-19 19:51:34 -04:00
alecmocatta 9d6e4f5ae6 Add tests 2019-09-06 17:38:28 -04:00
Diggory Hardy a04c750960 Make i128 support automatic for supporting Rustc versions
Uses autocfg
2019-01-28 09:59:18 -05:00
Ty Overby d8704644d7 format 2018-09-04 16:25:10 -07:00
boxdot 0e7b438bb4 Add tests for `Config::deserialize_seed`. 2018-09-04 16:22:50 -07:00
Ashley Mannix 2ef9a06894 add support for 128bit numbers 2018-05-30 09:44:38 -07:00
Ty Overby 76b7662dcd move to custom read implementation for deserialize_in_place 2018-02-07 19:39:27 -08:00
Ty Overby 68ca894b81 add deserialize_in_place 2018-02-07 18:32:10 -08:00
Ty Overby b31151a605 2nd implementation of the Config Trait (#214)
* add option and config traits

* thread options everywhere

* add WithOtherLimit, WithOtherEndian, and update internal to take advantage of it

* wip

* add rest of the public API and fix tests

* dtolnay feedback

* remove serialized_size_bounded and replace it with a use of config

* remove inline from trait method

* finish documentation and add custom reader support

* minor config_map refactor

* doc changes

* add with_(de)serializer functions and their associated modules
2018-02-07 18:26:46 -08:00
Markus Westerlind 7464ba7272 Allow serialized types to use a more compact representation ... (#217)
... by utilizing that bincode is not human readable.

Uses the changes in https://github.com/serde-rs/serde/pull/1044 which
allows data formats to report that they are not human readable. This
lets certain types serialize themselves into a more compact form as they
know that the serialized form does not need to be readable.

Closes #215

BREAKING CHANGE

This changes how types serialize themselves if they detect the
`is_human_readable` state.
2017-11-20 09:55:34 -08:00
Ty Overby 3a24da087b cargo fmt source 2017-10-13 08:57:04 -07:00
Ty Overby c8f02e30aa 177 invalid encodings (#212)
* split out invalid encoding errors

* detail breaking changes
2017-10-12 09:04:14 -07:00
Ty Overby 6692674f43 WIP Implement nocopy support for bincode (#150)
* basic infrastructure

* use BincodeRead internally

* fix zero copy behavior

* rearrange module layout; remove pub(crate)

* add size-limit safety checks when deserializing str or bytes

* fix-up tests
2017-04-20 18:27:22 -07:00
David Tolnay 7eccffd783 Update to serde 1.0 branch (#149)
* Update to serde 1.0 branch

* The serde 1.0 branch merged
2017-04-19 16:05:59 -07:00
Ty Overby 18cfe42d26 add more tests 2017-03-20 17:14:45 -07:00
Ty Overby 539637d78b remove refbox (#140) 2017-03-19 20:10:35 -07:00
Ty Overby f4c97fde6a make SizeLimit a trait (#124)
* make SizeLimit a trait

* move inline to the correct location
2017-03-17 17:59:12 -07:00
Ty Overby 1567d65ae9 fix oom 2017-02-24 19:04:46 -08:00
Ty Overby 1631cb2d80 Make Reader and Writer generic on Endianness (#103)
* Make Reader and Writer generic on Endianness

* make alternate API modules

* add test asserting that big endian encoding is different from little endian encoding

* clean up tests
2017-02-24 18:58:46 -08:00
Lena Hellström cac9301615 Remove InvalidEncoding struct (#111) 2017-02-10 10:19:58 -08:00
Lena Hellström ffbe4387dd Combine error types (#104)
* Combine error types

* Correct errors from merge conflict

* Create ErrorKind and Box it up

* Fix merge errors.

* Fix merge errors re-adding length encoding.
2017-02-09 23:07:20 -08:00
Ty Overby 19538cff29 Run tests on all channels (#108)
* Run tests on all channels

* try using travis.ci rust support
2017-02-03 09:54:39 -08:00
Lena Hellström 565b9c9f41 Remove length encoding (#102)
* Remove length encoding

* Improve bytes() test.
2017-02-03 09:27:03 -08:00
Ty Overby e7a74aa6c2 Remove rustc serialize support (#95)
* Remove rustc_serialize support

* Add changelist and bump version number for alpha

* Move refbox and friends into own module

* update changelog

* update travis config

* move serde functions out into global namespace
2017-01-31 15:50:55 -08:00
Lena Hellström c6393ac561 Update to serde 0.9.X (#93)
* Update to serde 0.9.X

* Remove redundant visitor and bad namespacing.

* Change DeserializeError to use Strings.

Reintroduce error tests.

* Better DeserializeError messages.

* Fix warnings.
2017-01-31 09:59:29 -08:00
David Tolnay 3d4346808f More efficient serialize_bytes (#90)
* Update to serde_derive

* Fix missing Encoder and Decoder imports

* Add test for serializing bytes

* More efficient serialize_bytes

Reported in #serde: blank_name2 tried serializing
`HashMap<String, HashSet<Bytes>>` vs `HashMap<String, HashSet<&Path>>`,
the `&Path` version was done in ~.6 seconds while the
`&[u8]` one took a full 3 seconds more.
2016-12-12 18:26:26 +00:00
Nikita Baksalyar 8d708cd194 Delegate emit_enum_struct_variant calls to emit_enum_variant (#89)
* Delegate emit_enum_struct_variant calls to emit_enum_variant

read_enum_struct_variant delegates calls to read_enum_variant which
expects u32 prefix to encode a variant number. Previous implementation
of emit_enum_struct_variant doesn't emit it, making serialized data
invalid.

* Add test to check manual enum encoding
2016-11-27 13:08:20 -08:00
Cobrand c5073e83e5 pub used InvalidEncoding in serde+rustc_serialize so it shows in `cargo doc` (#82)
* Removed unused import warning

* pub use InvalidEncoding in serde+rustc_serialize

* Made both fields of InvalidEncoding public so it can be used without Display or Debug traits (e.g. pattern matching)
* Export of InvalidEncoding in rustc_serialize/serde make them visible in `cargo doc`
2016-07-08 06:53:43 -07:00
Oliver Schneider 2eee182f1f fix char serialization and deserialization 2016-06-30 14:02:07 +02:00
Dmitry e5a524ed28 Fixed size array deserialization (#76)
* Attempt to implement hint for fixed size arrays.

* Removed wrong visitor + tests.

* Removed extra new line.
2016-06-19 13:29:10 -07:00
Ty Overby c819545c50 add more tests 2016-04-04 08:16:50 -07:00
Ty Overby bde9aa6565 add initial support for serde 0.7 2016-03-04 10:44:28 -08:00
Ty Overby 7662a57727 add more useful syntax error messages 2016-01-19 08:46:33 -08:00
Ty Overby 0cfb64511c moved the two designs into modules 2015-08-07 17:35:27 -07:00
Ty Overby 9c6bf1aa41 remove unused code 2015-08-07 16:39:15 -07:00
Ty Overby 3de218537f Fix test fallout during merge 2015-08-07 16:16:42 -07:00
Ty Overby 0c4403021d Merge branch 'serde3' of https://github.com/erickt/bincode into serde3 2015-08-07 15:14:38 -07:00
Ty Overby 022a9e6ed7 refactor test infrastructure 2015-08-07 15:14:20 -07:00
Erick Tryzelaar f04635c1ba Add newtype handlers to speed up parsing newtype structs and variants 2015-07-30 20:45:36 -07:00
Erick Tryzelaar 0d6b8a48b6 Get serde working 2015-07-29 13:15:04 -07:00
Erick Tryzelaar b206032ff1 Initial support for serde serialization 2015-07-01 15:21:26 -07:00
Erick Tryzelaar f11ba0c41f Move tests into the tests/ directory 2015-06-30 07:52:18 -07:00