serde-rs/bytes


Wrapper types to enable optimized handling of &[u8] and Vec<u8>

License: Apache-2.0

Language: Rust


serde_bytes Build Status Latest Version

Wrapper types to enable optimized handling of &[u8] and Vec<u8>.

[dependencies]
serde_bytes = "0.11"

Explanation

Without specialization, Rust forces Serde to treat &[u8] just like any other slice and Vec<u8> just like any other vector. In reality this particular slice and vector can often be serialized and deserialized in a more efficient, compact representation in many formats.

When working with such a format, you can opt into specialized handling of &[u8] by wrapping it in serde_bytes::Bytes and Vec<u8> by wrapping it in serde_bytes::ByteBuf.

Additionally this crate supports the Serde with attribute to enable efficient handling of &[u8] and Vec<u8> in structs without needing a wrapper type.

Example

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
struct Efficient<'a> {
    #[serde(with = "serde_bytes")]
    bytes: &'a [u8],

    #[serde(with = "serde_bytes")]
    byte_buf: Vec<u8>,
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Project Statistics

Sourcerank 16
Repository Size 227 KB
Stars 300
Forks 34
Watchers 8
Open issues 9
Dependencies 4
Contributors 9
Tags 24
Created
Last updated
Last pushed

Top Contributors See all

0xZensh Xiretza sosthene-nitrokey hcpl sgued Nathan West Martin Disch Dirkjan Ochtman

Packages Referencing this Repo

serde_bytes
Optimized handling of `&[u8]` and `Vec<u8>` for Serde
Latest release 0.11.14 - Updated - 300 stars

Recent Tags See all

0.11.15 June 25, 2024
0.11.14 January 02, 2024
0.11.13 December 27, 2023
0.11.12 July 15, 2023
0.11.11 July 05, 2023
0.11.10 July 03, 2023
0.11.9 February 05, 2023
0.11.8 December 17, 2022
0.11.7 August 03, 2022
0.11.6 April 30, 2022
0.11.5 June 11, 2020
0.11.4 May 02, 2020
0.11.3 December 04, 2019
0.11.2 August 07, 2019
0.11.1 April 07, 2019

Interesting Forks See all

ChainSafe/serde-bytes
Wrapper types to enable optimized handling of &[u8] and Vec<u8>
Rust - Apache-2.0 - Last pushed - 1 stars - 1 forks

Something wrong with this page? Make a suggestion

Last synced: 2024-08-09 18:02:26 UTC

Login to resync this repository