Commit Graph

351 Commits

Author SHA1 Message Date
Gino Valente c179d2de69 Allow decode with custom DeserializeSeed (#586) 2022-10-02 11:35:16 +02:00
Vincent Rouillé 1b5eab9fcf Extended BorrowDecode for HashMap to support custom hashers (#585) 2022-10-02 10:12:14 +02:00
trevyn 6d995a74c7 Document configuration generics (#581)
Co-authored-by: Trangar <gpg@trangar.com>
2022-09-28 08:00:40 +00:00
Gerd Zellweger 954abe415e Implement Encode for tuples with up-to 16 elements. (#583)
This makes it match the implementation for Decode which is
already supports up to 16 fields.

Signed-off-by: Gerd Zellweger <mail@gerdzellweger.com>

Signed-off-by: Gerd Zellweger <mail@gerdzellweger.com>
2022-09-28 09:42:04 +02:00
trevyn cafb13eb95 Clarify config::legacy() doc to match config::standard() (#580) 2022-09-17 17:22:31 +02:00
Gimgim ac44658bfb Document what the usizes are for (#546) (#577)
* Document what the usize is for

* Document the usize

Co-authored-by: Trangar <gpg@trangar.com>
2022-08-18 17:47:19 +00:00
Trangar c763e2f11e Implement Default for Configuration (#575) 2022-08-18 17:14:07 +00:00
Trangar 88ab23f544 Made `peek_read` take `&mut self` (#572) 2022-08-18 16:54:21 +02:00
Trangar 974abe8661 Fixed the clippy Eq warning. (#574)
Added DecodeError::Io
Removed `PartialEq` on DecodeError
2022-08-18 15:57:18 +02:00
Sabrina Jewson 035baf735f Implement `Decode` for `Box<str>` (#562) 2022-07-23 11:56:42 +02:00
Maciej Hirsz bd07adea66 Shrink `DecodeError` from 48 to 32 bytes on 64-bit arch (#553)
* Shrink `DecodeError` to 32 bytes on 64-bit arch

* Nul with a single l

* fmt

* Consider feature combinations for error sizes

* Remove superfluous `any`

* fmt

* Box SystemTime in EncodeError
2022-06-15 20:50:09 +02:00
Maciej Hirsz 229b597a84 Add impls for Rc<[T]> and Arc<[T]> (#552) 2022-06-15 07:47:26 +02:00
Lúcás Meier 357d7d3c0e Add impl Encode for [T], where T: Encode (#542)
* Add impl Encode for [T], where T: Encode

Since Encode takes a reference, this allows us to encode &[T] directly
using this implementation. The encoding scheme is the same as for
Vec<T>.

This also makes the implementation for &[u8] superfluous, since we get
an implementation for [u8] by virtue of u8 implementing encode. This
also gives us free implementations for &[u16], &[u32], etc. which is
quite useful. Nonetheless, we keep the implementation for &[u8] around,
because the implementation can directly write a large number of bytes,
which can be more efficient than the generic implementation.

* Remove redundant Encode implementations

Since we've implemented Encode for [T], this makes the implementation
for Box<[T]> redundant (since we have a blanket implementation for
Box<T>), and ditto for &[T], which this change replaces by combining the
implementations for [T] and &T.

* Reinclude comment about Encode specialization for &[u8]
2022-06-05 18:41:43 +02:00
Trangar 86e03aeda7 Rewrite: seperated Decode and BorrowDecode (#526)
* Rewrite: seperated Decode and BorrowDecode

* Fixed cargo.toml issues

* Fixed clippy warning

* Removed the `impl_tuples` macro call with manually exported code

* Replaced the generated code in `impl_tuples` with the macro instead

* Implemented BorrowDecode for Box<[T]>

* Added a test to see if zoxide can be ported to bincode 2

* Added a test for Arc<str>

* Made several `Encode` implementations require `T: ?Sized`

* Implemented Decode for Arc<str>

* Added BlockedTODO links to commented out code

* Fixed clippy and lint issues

* Updated virtue dependency in fuzz lockfile
2022-06-04 15:23:55 +02:00
Lena Hellström f979383adb Fix tuple struct encoding in serde (#549) 2022-06-04 14:56:20 +02:00
Trangar e7d2292dc2 Switched to weak dependencies (#538)
* Switched to weak dependencies

* Removed old `serde_impl` references

* Fixed CI and updated documentation

* Fixed a cfg for a test

* Removed unneeded package in Cargo.toml
2022-05-21 14:19:13 +02:00
Sean Cross d7edfaa0b7 Fix riscv32 atomics and fix tests on 32-bit platforms (#533)
* tests: fix alloc range test on 32-bit Windows

This test checks the range, which is necessarily different when running
on another platform.

Signed-off-by: Sean Cross <sean@xobs.io>

* enc: case usize/isize as u64/i64 in serialization

The deserialization process assumes that usize/isize are 64-bits, as
does the spec at
https://github.com/bincode-org/bincode/blob/trunk/docs/spec.md#varintencoding

Force `usize` and `isize` to be encoded as `u64` and `i64` to force
32-bit platforms to conform to this spec.

This fixes running tests under `cargo test --target i686-pc-windows-msvc`

Signed-off-by: Sean Cross <sean@xobs.io>

* atomic: only provide Atomic*64 on supported platforms

Not all platforms support AtomicI64 or AtomicU64. Use the
`target_has_atomic` config flag to determine whether to include these.

This fixes #532.

Signed-off-by: Sean Cross <sean@xobs.io>

* atomic: remove feature and use new attributes

Now that there is an attribute to indicate which atomic features are
supported on this platform, remove the `atomic` Feature and use these
new attributes.

Signed-off-by: Sean Cross <sean@xobs.io>

* alloc: run `cargo fmt`

Signed-off-by: Sean Cross <sean@xobs.io>
2022-04-08 11:35:13 +02:00
Trangar 883278fa0c Added cross platform tests workflow (#534)
* Added cross platform tests

* Added all cross platforms

* Fixed an issue where `usize` and `isize` would be encoded wrong on 32 bit platforms

* Made the cross platform tests actually run on the platforms

* Disabled cross targets that don't build right now

* Fixed a failing test on 32 bit platforms, re-enabled all platforms for testing

* Disabled failing platforms
2022-04-04 14:09:42 +02:00
Trangar 36e45d26eb Added `std::error::Error::source` (#530) 2022-04-04 13:58:18 +02:00
Bronson Philippa 49c8d1148f Extended Encode and Decode for HashMap and HashSet to support custom hashers (#529) 2022-03-28 12:19:33 +02:00
Trangar 6693276e95 Added `additional` to the `UnexpectedEnd` decode error (#522) 2022-03-17 11:40:10 +01:00
Trangar a7fba80e23 Made the Cow Encode constraints more permissive (#524)
* Made the Cow Encode constraints more permissive

* Made Decode more permissive for Cow
2022-03-17 11:31:22 +01:00
Trangar fe611f77c0 Release 2.0.0-rc.1 (#510) 2022-03-04 11:05:38 +01:00
Trangar caa71b5d9f Added HashSet (#516)
* Added HashSet

* Added hashset to the same tests that hashmap has
2022-03-03 15:23:53 +01:00
Trangar 03450ac49f Made config::standard() implement .write_fixed_array_header() by default (#509)
* Made config::standard() implement .write_fixed_array_header() by default

* Fixed failing unit test

* Fixed formatting
2022-02-28 17:26:46 +01:00
Pietro 1c5041390f Add reference implementation for Writer and remove unnecessary lifetimes from Reader's one (#507) 2022-02-23 11:08:28 +01:00
Trangar 7c72e4c1fa Release v2.0.0-beta.3 (#505) 2022-02-16 12:53:44 +01:00
Trangar 58dc788dfa Fix/issue 500 (#503)
* Fixed an issue where serde would decode a sequence with an u32 instead of a usize

* Added serde to the `the_same` test for roundtrips, fixed several issues.

* Fixed backwards compatibility for result, ipv4addr and ipv6addr

* Processed feedback
2022-02-07 16:52:15 +01:00
Lena Hellström cbad043a53 Fix CString compatibility with bincode v1 (#502) 2022-02-06 10:36:03 +01:00
poljar d90f501872 Return an error if a decoded slice length doesn't fit into usize (#491)
* Return an error if a decoded slice length doesn't fit into usize

Bincode encodes a slice length, which is an usize, as an u64. When such
an encoded slice length needs to be decoded it again uses an u64 but
critically it truncates it into an usize.

An usize is architecture dependent, it is the size how many bytes it takes to
reference any location in memory. The most common sizes for an usize are 64, 32,
and 16 bit.

This might lead to silent data loss if the architecture that encoded the
slice differs from the architecture that decoded the slice, i.e. if we
go from a 64 bit architecture to a 32 or 16 bit one.

Since bincode aims to be suitable for storage, aiming to support the
exchange of data between different architectures silently truncating
such slice lenghts should be avoided.

This patch changes the behaviour to error out if we try to decode an
slice lenght that can't fit into the current usize type.

* Remove another two usize truncations

* Rename the error variant if the usize doesn't fit anymore

Co-authored-by: Trangar <victor.koenders@gmail.com>
2022-01-25 17:49:26 +01:00
poljar 306a772835 Fix a bunch of typos (#492) 2022-01-25 12:13:38 +01:00
Trangar 3c64d7dbbe Added a table to the documentation to pick which functions to use (#490)
* Added a table to the documentation to pick which functions to use

* Forgot cargo fmt

* Added a line on custom readers and writers
2022-01-24 16:45:41 +01:00
Trangar 25dd4debc4 Release v2.0.0-beta.2 (#488) 2022-01-23 10:15:00 +01:00
Trangar 20e4a02ea3 Added #[serde(untagged)] to the documentation of attributes that don't work (#486) 2022-01-23 10:05:54 +01:00
Trangar 09e7a6265d Release v2.0.0-beta.1 (#484) 2022-01-19 19:11:35 +01:00
Trangar a00f37ee59 Migration guide (#482)
* Added a guide on how to migrate from bincode 1 to 2

* Removed unneeded dependency on bincode 1

* Processed feedback

* Added a link to the migration guide, added `#[cfg(doc)]` to the doc modules
2022-01-19 19:04:20 +01:00
Trangar d13d177bea made the serde functions consistent with the base bincode functions (#483) 2022-01-19 18:57:52 +01:00
Trangar fc1f3acdcb Feature/improve serde (#477)
* Made serde able to be used with alloc and no_std targets

* Processed feedback
2022-01-19 18:14:21 +01:00
Trangar 59b787cbf8 Moved Configuration::standard() and ::legacy() to the config module (#481)
* Moved Configuration::standard() and ::legacy() to the config module

* Fixed issue with config that would overwrite the limit, added a checklist on adding config variables
2022-01-19 16:46:25 +01:00
Trangar a5e57d51d8 Update documentation (#480)
* Updated documentation

* Updated spec.md
2022-01-18 15:17:58 +01:00
Trangar f3c21f2245 Made SerdeDecoder attempt to allocate a string before complaining about being able to decode borrowed data (#475) 2022-01-17 17:16:14 +01:00
Trangar c1e9828e7d Implemented the newly stabilized CString::from_vec_with_nul method (#473) 2022-01-13 20:52:51 +01:00
Lena Hellström 8106eadf66 Switch Encode to take &mut E (#471) 2022-01-13 12:26:09 +01:00
Trangar 4149c0f29f Switched Decode and BorrowDecode to take &mut D (#470)
* Switched Decode and BorrowDecode to take &mut D, fixes #467

* I didn't forget to run cargo fmt, you did
2022-01-11 20:23:31 +01:00
5225225 39ba03b2e5 Fix panic with invalid system time (#469) 2022-01-09 14:54:51 +01:00
5225225 236d350f13 Fix overflow error when deserializing invalid Duration (#465)
* Fix overflow error when deserializing invalid Duration

* Use unwrap_err instead of match in test
2022-01-08 22:54:04 +01:00
Trangar a08e528cc7 Release v2.0.0-beta.0 (#464) 2022-01-08 15:42:49 +01:00
Trangar 99707d0d0b Fixed derive impl on an empty enum (#462)
* Fixed derive impl on an empty enum

* Added DecodeError::EmptyEnum in case a user tries to decode an empty enum
2022-01-08 12:39:03 +01:00
Popog dbb9a43ccd feat: Make `Configuration` functions `const` (#456) 2021-12-16 09:53:15 +01:00
Trangar 45c0fa7782 Release v2.0.0-alpha.2 (#455) 2021-12-14 15:27:40 +01:00