-
Notifications
You must be signed in to change notification settings - Fork 72
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 a Bytes
type for more efficient byte sequences
#277
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jonasbb
force-pushed
the
bytes
branch
2 times, most recently
from
March 11, 2021 23:40
182b0a9
to
d2c07b4
Compare
Codecov Report
@@ Coverage Diff @@
## master #277 +/- ##
==========================================
- Coverage 76.70% 74.68% -2.03%
==========================================
Files 40 40
Lines 2142 2200 +58
==========================================
Hits 1643 1643
- Misses 499 557 +58
Continue to review full report at Codecov.
|
The `Bytes` type is heavily inspired by `serde_bytes` and ports it to the serde_as system. ```rust value: Vec<u8>, ``` Compared to `serde_bytes` these improvements are available 1. Integration with the `serde_as` annotation. /cc serde-rs/bytes#14 2. Implementation for arrays of arbitrary size (Rust 1.51+). /cc serde-rs/bytes#26
bors r+ |
Build succeeded: |
bors bot
added a commit
that referenced
this pull request
Jun 14, 2021
325: Bytes const size borrowed arrays r=jonasbb a=matix2267 Currently `Bytes` (added in #277) supports some const size array types (e.g. `[u8; N]` and `Box<[u8; N]>`) but not others (e.g. `&[u8; N]` and `Cow<'_, [u8; N]>`). This pull request implements `Bytes` support for `&[u8; N]` and `Cow<'_, [u8; N]>` This bring parity between dynamic and const sized types. ### Before: | Sizing | Owned | Borrowed | Cow | Box | | ------- | -------------- | ------------- | --------------------- | ----------------- | | Const | ✅ `[u8; N]` | ❌ `&[u8; N]` | ❌ `Cow<'_, [u8; N]>` | ✅ `Box<[u8; N]>` | | Dynamic | ✅ `Vec<u8>`\* | ✅ `&[u8]` | ✅ `Cow<'_, [u8]>` | ✅ `Box<[u8]>` | ### After: | Sizing | Owned | Borrowed | Cow | Box | | ------- | -------------- | ------------- | --------------------- | ----------------- | | Const | ✅ `[u8; N]` | ✅ `&[u8; N]` | ✅ `Cow<'_, [u8; N]>` | ✅ `Box<[u8; N]>` | | Dynamic | ✅ `Vec<u8>`\* | ✅ `&[u8]` | ✅ `Cow<'_, [u8]>` | ✅ `Box<[u8]>` | I've also added a separate commit with an example of using fully borrowed types, but that example only does serialization because RON doesn't support 0-copy deserialization for byte arrays (as it needs to decode them from base64). Because of that I'm not sure if this example is useful so feel free to merge only the main commit. <sub>\* Technically `[u8]` corresponds to `[u8; N]` but `[u8]` is an un`Sized` type and cannot be directly used in structs.</sub> Co-authored-by: matix2267 <[email protected]>
This was referenced Dec 19, 2022
bors bot
added a commit
that referenced
this pull request
Dec 24, 2022
536: Mention "Bytes" on README.md and lib.rs r=jonasbb a=ryoqun I think #277 can be more promoted. :) As I wrote the current status of serialization of const generics like bytes (solana-labs/solana#29196 (comment)), i think `"Bytes"` is best solution so far. `@jonasbb` hey, this functionary saved us. however it took a while to spot this. I think `Bytes` can be promoted. :) Co-authored-by: Ryo Onodera <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
Bytes
type is heavily inspired byserde_bytes
and ports it to theserde_as system.
Compared to
serde_bytes
these improvements are availableserde_as
annotation./cc Working with more complex types is difficult serde-rs/bytes#14
/cc Implement (de-)serializing for
[u8; N]
serde-rs/bytes#26