-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for [u8; N]
#28
Conversation
I'd love to see this added, would it be possible for a maintainer to have a look at it? |
e3a2120
to
846ccba
Compare
I am also really interested in this. Any chance you could have a look @dtolnay ? |
7b125bc
to
1bdc428
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
It is based on serde-rs/bytes#28 which is not yet merged. Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Note that unlike |
…uid. Squashed commit of the following: commit 3a1fac3 Author: Martin Tzvetanov Grigorov <[email protected]> Date: Fri Oct 7 10:48:13 2022 +0300 AVRO-3631: Use official serde_bytes crate Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> commit f7f0ec5 Author: Martin Tzvetanov Grigorov <[email protected]> Date: Thu Oct 6 14:01:19 2022 +0300 AVRO-3631: Fix clippy issues Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> commit 0ee5b00 Author: Martin Tzvetanov Grigorov <[email protected]> Date: Thu Oct 6 13:38:10 2022 +0300 AVRO-3631: Add more test cases Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> commit 70d6cf0 Author: Martin Tzvetanov Grigorov <[email protected]> Date: Thu Oct 6 12:05:08 2022 +0300 AVRO-3631: Fix clippy and Rat issues Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> commit 7c9e938 Author: Martin Tzvetanov Grigorov <[email protected]> Date: Thu Oct 6 11:45:50 2022 +0300 AVRO-3631: Add serde serialize_with functions Those should be used for hinting the serialization process how to serialize a byte array to Value::(Bytes|Fixed) Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> commit 3e3f125 Author: Martin Tzvetanov Grigorov <[email protected]> Date: Mon Oct 3 23:45:11 2022 +0300 AVRO-3631: Use #[serde(with)] attribute to get rid of implementation detail ByteArray Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> commit 7b1cdd8 Author: Martin Tzvetanov Grigorov <[email protected]> Date: Mon Oct 3 14:52:24 2022 +0300 AVRO-3631: Add support for ser_de Value::Fixed It is based on serde-rs/bytes#28 which is not yet merged. Signed-off-by: Martin Tzvetanov Grigorov <[email protected]> commit 5c2d197 Author: Rik Heijdens <[email protected]> Date: Thu Sep 29 14:15:49 2022 +0200 AVRO-3631: Reformat using rustfmt commit a31fcfc Author: Rik Heijdens <[email protected]> Date: Thu Sep 29 14:14:35 2022 +0200 AVRO-3631: Add test for serializing fixed fields This test-case mainly demonstrates the issue reported in AVRO-3631. It is unclear to me whether we should actually expect the serializer to serialize to a Value::Fixed right away given that Schema information is not available at this stage. commit 12ef14b Author: Rik Heijdens <[email protected]> Date: Thu Sep 29 14:12:51 2022 +0200 AVRO-3651: Add test to de.rs to illustrate issue with Fixed fields commit d32d436 Author: Rik Heijdens <[email protected]> Date: Wed Sep 28 15:48:29 2022 +0200 AVRO-3631: Add test-case to reproduce
This is blocking downstream feature in Avro/Rust for Fixed Types. Can this be merged soon please ? |
Haha, I created a pull request with almost exactly the same name, not realizing that this existed (I'll delete it now). |
It is based on serde-rs/bytes#28 which is not yet merged. Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Given the lack of activity in this PR we published a similar crate specifically for |
The |
It is based on serde-rs/bytes#28 which is not yet merged. Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
It is based on serde-rs/bytes#28 which is not yet merged. Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Does anyone know why this is taking so long? |
in case anyone looking for drop-in replacement with all bytes/slice support in one crate, can use this https://github.com/so-schen/serde-bytes-ng |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This looks great, especially with Lucretiel great suggestions.
It is based on serde-rs/bytes#28 which is not yet merged. Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
It is based on serde-rs/bytes#28 which is not yet merged. Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
Hi.
This PR adds support for constant length byte arrays
[u8; N]
and adds aByteArray<const N: usize>
wrapper type similar toBytesBuf
. This would close #26.Motivations
Fixed sized array are often used for cryptography and embedded systems. Having efficient support to serialize/deserialize keys would be great.
Parts of the PR requiring discussion
I'm not sure why
ByteBuf
andBytes
implementsPartialEq
andPartialOrd
for types implementingAsRef<[u8]>
and notBorrow<[u8]>
. ByteArray implementsPartialEq
/Ord
with types implementingBorrow<[u8; N]>
so that it can be compared to itself and to[u8; N]
It might be worth considering adding a
new_mut(&mut [u8]) -> Bytes
function toBytes
so that the same (unsafe) code is reused for theBorrowMut<Bytes>
implementations ofByteArray
andByteBuf
.Drawbacks
Due to the use of const generics, this would require raising the MSRV to 1.53 (which could be lowered to 1.51 by removing the
IntoIterator
implementation).Edit: Since 0504fcb already bumped MSRV to 1.56, this drawback doesn't apply anymore.