diff options
author | Joel Galenson <jgalenson@google.com> | 2021-10-14 18:37:12 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-10-14 18:37:12 +0000 |
commit | f6c300a543ca28954f8d9ba8bf59d29585c02c19 (patch) | |
tree | 7b935046e15a3c4c4e0143985d17fb61c42513f1 | |
parent | 3233eba52db5ebab3928105b218755c9f868d064 (diff) | |
parent | 0b0733c947e4fe4796b3c58ddd8c1343a44ef2d9 (diff) | |
download | serde_cbor-f6c300a543ca28954f8d9ba8bf59d29585c02c19.tar.gz |
Upgrade rust/crates/serde_cbor to 0.11.2 am: 257082937a am: 09d1d83d03 am: 0b0733c947
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/serde_cbor/+/1833618
Change-Id: I7c2652d9de0f234ba2ac388b077edfada7076f8b
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .editorconfig | 5 | ||||
-rw-r--r-- | Android.bp | 8 | ||||
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | Cargo.toml.orig | 6 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | README.md | 20 | ||||
-rw-r--r-- | src/lib.rs | 62 | ||||
-rw-r--r-- | src/tags.rs | 3 |
9 files changed, 101 insertions, 21 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index efb3a6e..6009691 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "eddd181447c25722fa294dc2c1be8c1881b105eb" + "sha1": "347a3f096d5a1e8e380b9968e74838c9037a5b14" } } diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5122b87 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +# see https://editorconfig.org for more options, and setup instructions for yours editor + +[*.rs] +indent_style = space +indent_size = 4 @@ -1,4 +1,4 @@ -// This file is generated by cargo2android.py --run --device --dependencies --tests --features default,tags. +// This file is generated by cargo2android.py --run --device --tests --features default,tags. // Do not modify this file as changes will be overridden on upgrade. package { @@ -42,7 +42,7 @@ rust_library { host_supported: true, crate_name: "serde_cbor", cargo_env_compat: true, - cargo_pkg_version: "0.11.1", + cargo_pkg_version: "0.11.2", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -61,7 +61,7 @@ rust_defaults { crate_name: "serde_cbor", srcs: ["src/lib.rs"], cargo_env_compat: true, - cargo_pkg_version: "0.11.1", + cargo_pkg_version: "0.11.2", test_suites: ["general-tests"], auto_gen_config: true, edition: "2018", @@ -94,7 +94,7 @@ rust_defaults { name: "serde_cbor_test_defaults_serde_cbor", crate_name: "serde_cbor", cargo_env_compat: true, - cargo_pkg_version: "0.11.1", + cargo_pkg_version: "0.11.2", test_suites: ["general-tests"], auto_gen_config: true, edition: "2018", @@ -13,8 +13,8 @@ [package] edition = "2018" name = "serde_cbor" -version = "0.11.1" -authors = ["Pyfisch <pyfisch@gmail.com>", "Steven Fackler <sfackler@gmail.com>"] +version = "0.11.2" +authors = ["Pyfisch <pyfisch@posteo.org>", "Steven Fackler <sfackler@gmail.com>"] description = "CBOR support for serde." readme = "README.md" keywords = ["serde", "cbor", "serialization", "no_std"] @@ -38,7 +38,7 @@ std = ["serde/std"] tags = [] unsealed_read_write = [] [badges.maintenance] -status = "passively-maintained" +status = "as-is" [badges.travis-ci] repository = "pyfisch/cbor" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 8b5c14c..52e1657 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,8 +1,8 @@ [package] name = "serde_cbor" -version = "0.11.1" +version = "0.11.2" authors = [ - "Pyfisch <pyfisch@gmail.com>", + "Pyfisch <pyfisch@posteo.org>", "Steven Fackler <sfackler@gmail.com>"] repository = "https://github.com/pyfisch/cbor" readme = "README.md" @@ -14,7 +14,7 @@ edition = "2018" [badges] travis-ci = { repository = "pyfisch/cbor" } -maintenance = { status = "passively-maintained" } +maintenance = { status = "as-is" } [dependencies] half = "1.2.0" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/serde_cbor/serde_cbor-0.11.1.crate" + value: "https://static.crates.io/crates/serde_cbor/serde_cbor-0.11.2.crate" } - version: "0.11.1" + version: "0.11.2" license_type: NOTICE last_upgrade_date { - year: 2020 - month: 12 - day: 21 + year: 2021 + month: 9 + day: 22 } } @@ -3,6 +3,24 @@ [![Crates.io](https://img.shields.io/crates/v/serde_cbor.svg)](https://crates.io/crates/serde_cbor) [![Documentation](https://docs.rs/serde_cbor/badge.svg)](https://docs.rs/serde_cbor) +## PROJECT IS ARCHIVED + +After almost 6 years it is time to retire this crate. +This implementation of CBOR for serde is used in hundreds of projects with widely differing needs. +Besides the standard features it contains code for no-std environments, a packed encoding and CBOR tags. +However while these features are useful to many people they sometimes interact poorly with each others and with optional features of serde itself. +Because I don't use the crate myself and because of the potential for new errors I have been reluctant to accept any changes or additional features for the crate. +Since this situation is unlikely to change anytime soon and no one else stepped up to maintain this crate I am archiving the repository today. +If the crate works for you there is no need to switch to another implementation. +However if you encounter problems or for new projects I recommend you take a look at these crates: + +* [ciborium](https://crates.io/crates/ciborium) +* [minicbor](https://crates.io/crates/minicbor) + +~~ Pyfisch, August 2021 + + + This crate implements the Concise Binary Object Representation from [RFC 7049]. It builds on [Serde], the generic serialization framework for Rust. CBOR provides a binary encoding for a superset @@ -16,7 +34,7 @@ of the JSON data model that is small and very fast to parse. Serde CBOR supports Rust 1.40 and up. Add this to your `Cargo.toml`: ```toml [dependencies] -serde_cbor = "0.11.1" +serde_cbor = "0.11.2" ``` Storing and loading Rust types is easy and requires only @@ -66,11 +66,20 @@ //! # Packed Encoding //! When serializing structs or enums in CBOR the keys or enum variant names will be serialized //! as string keys to a map. Especially in embedded environments this can increase the file -//! size too much. In packed encoding the keys and variants will be serialized as variable sized -//! integers. The first 24 entries in any struct consume only a single byte! +//! size too much. In packed encoding all struct keys, as well as any enum variant that has no data, +//! will be serialized as variable sized integers. The first 24 entries in any struct consume only a +//! single byte! Packed encoding uses serde's preferred [externally tagged enum +//! format](https://serde.rs/enum-representations.html) and therefore serializes enum variant names +//! as string keys when that variant contains data. So, in the packed encoding example, `FirstVariant` +//! encodes to a single byte, but encoding `SecondVariant` requires 16 bytes. +//! //! To serialize a document in this format use `Serializer::new(writer).packed_format()` or //! the shorthand `ser::to_vec_packed`. The deserialization works without any changes. //! +//! If you would like to omit the enum variant encoding for all variants, including ones that +//! contain data, you can add `legacy_enums()` in addition to `packed_format()`, as can seen +//! in the Serialize using minimal encoding example. +//! //! # Self describing documents //! In some contexts different formats are used but there is no way to declare the format used //! out of band. For this reason CBOR has a magic number that may be added before any document. @@ -132,6 +141,55 @@ //! # } //! ``` //! +//! Serialize using packed encoding +//! +//! ```rust +//! use serde_derive::{Deserialize, Serialize}; +//! use serde_cbor::ser::to_vec_packed; +//! use WithTwoVariants::*; +//! +//! #[derive(Debug, Serialize, Deserialize)] +//! enum WithTwoVariants { +//! FirstVariant, +//! SecondVariant(u8), +//! } +//! +//! let cbor = to_vec_packed(&FirstVariant).unwrap(); +//! assert_eq!(cbor.len(), 1); +//! +//! let cbor = to_vec_packed(&SecondVariant(0)).unwrap(); +//! assert_eq!(cbor.len(), 16); // Includes 13 bytes of "SecondVariant" +//! ``` +//! +//! Serialize using minimal encoding +//! +//! ```rust +//! use serde_derive::{Deserialize, Serialize}; +//! use serde_cbor::{Result, Serializer, ser::{self, IoWrite}}; +//! use WithTwoVariants::*; +//! +//! fn to_vec_minimal<T>(value: &T) -> Result<Vec<u8>> +//! where +//! T: serde::Serialize, +//! { +//! let mut vec = Vec::new(); +//! value.serialize(&mut Serializer::new(&mut IoWrite::new(&mut vec)).packed_format().legacy_enums())?; +//! Ok(vec) +//! } +//! +//! #[derive(Debug, Serialize, Deserialize)] +//! enum WithTwoVariants { +//! FirstVariant, +//! SecondVariant(u8), +//! } +//! +//! let cbor = to_vec_minimal(&FirstVariant).unwrap(); +//! assert_eq!(cbor.len(), 1); +//! +//! let cbor = to_vec_minimal(&SecondVariant(0)).unwrap(); +//! assert_eq!(cbor.len(), 3); +//! ``` +//! //! # `no-std` support //! //! Serde CBOR supports building in a `no_std` context, use the following lines diff --git a/src/tags.rs b/src/tags.rs index 50e039e..8adccb8 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -42,8 +42,7 @@ fn untagged<T>(value: T) -> Tagged<T> { macro_rules! delegate { ($name: ident, $type: ty) => { - fn $name<E: serde::de::Error>(self, v: $type) -> Result<Self::Value, E> - { + fn $name<E: serde::de::Error>(self, v: $type) -> Result<Self::Value, E> { T::deserialize(v.into_deserializer()).map(untagged) } }; |