diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-10 07:04:56 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-10 07:04:56 +0000 |
commit | 99fc25748205b6205b18b6dcb689b1281e15a118 (patch) | |
tree | d18a3f03fce2bcb7c7025fda0dde71d60fc3d0b5 | |
parent | 60df212addabfd7f67599ef8e07f3f3d0e5416fb (diff) | |
parent | 271052b6f25978489bcf3e1bb688cd7f2e93c8de (diff) | |
download | serde_cbor-aml_wif_330910030.tar.gz |
Snap for 8564071 from 271052b6f25978489bcf3e1bb688cd7f2e93c8de to mainline-wifi-releaseaml_wif_331910020aml_wif_331810010aml_wif_331710030aml_wif_331613000aml_wif_331511020aml_wif_331414000aml_wif_331310070aml_wif_331112000aml_wif_331016070aml_wif_330910030aml_wif_330810040android13-mainline-wifi-release
Change-Id: Ie7b9374a2115d2614cde46b41cef4169f3de38e9
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .editorconfig | 5 | ||||
-rw-r--r-- | Android.bp | 141 | ||||
-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-- | TEST_MAPPING | 91 | ||||
-rw-r--r-- | cargo2android.json | 7 | ||||
-rw-r--r-- | src/lib.rs | 62 | ||||
-rw-r--r-- | src/tags.rs | 3 |
11 files changed, 220 insertions, 133 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. +// This file is generated by cargo2android.py --config cargo2android.json. // Do not modify this file as changes will be overridden on upgrade. package { @@ -41,58 +41,34 @@ rust_library { name: "libserde_cbor", host_supported: true, crate_name: "serde_cbor", + cargo_env_compat: true, + cargo_pkg_version: "0.11.2", srcs: ["src/lib.rs"], edition: "2018", features: [ "default", "std", + "tags", ], rustlibs: [ "libhalf", "libserde", ], + vendor_available: true, } rust_defaults { - name: "serde_cbor_defaults", - crate_name: "serde_cbor", - srcs: ["src/lib.rs"], - test_suites: ["general-tests"], - auto_gen_config: true, - edition: "2018", - features: [ - "default", - "std", - ], - rustlibs: [ - "libhalf", - "libserde", - ], - proc_macros: ["libserde_derive"], -} - -rust_test_host { - name: "serde_cbor_host_test_src_lib", - defaults: ["serde_cbor_defaults"], - test_options: { - unit_test: true, - }, -} - -rust_test { - name: "serde_cbor_device_test_src_lib", - defaults: ["serde_cbor_defaults"], -} - -rust_defaults { - name: "serde_cbor_defaults_serde_cbor", + name: "serde_cbor_test_defaults", crate_name: "serde_cbor", + cargo_env_compat: true, + cargo_pkg_version: "0.11.2", test_suites: ["general-tests"], auto_gen_config: true, edition: "2018", features: [ "default", "std", + "tags", ], rustlibs: [ "libhalf", @@ -102,9 +78,10 @@ rust_defaults { proc_macros: ["libserde_derive"], } -rust_test_host { - name: "serde_cbor_host_test_tests_bennofs", - defaults: ["serde_cbor_defaults_serde_cbor"], +rust_test { + name: "serde_cbor_test_tests_bennofs", + defaults: ["serde_cbor_test_defaults"], + host_supported: true, srcs: ["tests/bennofs.rs"], test_options: { unit_test: true, @@ -112,14 +89,9 @@ rust_test_host { } rust_test { - name: "serde_cbor_device_test_tests_bennofs", - defaults: ["serde_cbor_defaults_serde_cbor"], - srcs: ["tests/bennofs.rs"], -} - -rust_test_host { - name: "serde_cbor_host_test_tests_canonical", - defaults: ["serde_cbor_defaults_serde_cbor"], + name: "serde_cbor_test_tests_canonical", + defaults: ["serde_cbor_test_defaults"], + host_supported: true, srcs: ["tests/canonical.rs"], test_options: { unit_test: true, @@ -127,14 +99,9 @@ rust_test_host { } rust_test { - name: "serde_cbor_device_test_tests_canonical", - defaults: ["serde_cbor_defaults_serde_cbor"], - srcs: ["tests/canonical.rs"], -} - -rust_test_host { - name: "serde_cbor_host_test_tests_de", - defaults: ["serde_cbor_defaults_serde_cbor"], + name: "serde_cbor_test_tests_de", + defaults: ["serde_cbor_test_defaults"], + host_supported: true, srcs: ["tests/de.rs"], test_options: { unit_test: true, @@ -142,14 +109,9 @@ rust_test_host { } rust_test { - name: "serde_cbor_device_test_tests_de", - defaults: ["serde_cbor_defaults_serde_cbor"], - srcs: ["tests/de.rs"], -} - -rust_test_host { - name: "serde_cbor_host_test_tests_enum", - defaults: ["serde_cbor_defaults_serde_cbor"], + name: "serde_cbor_test_tests_enum", + defaults: ["serde_cbor_test_defaults"], + host_supported: true, srcs: ["tests/enum.rs"], test_options: { unit_test: true, @@ -157,14 +119,9 @@ rust_test_host { } rust_test { - name: "serde_cbor_device_test_tests_enum", - defaults: ["serde_cbor_defaults_serde_cbor"], - srcs: ["tests/enum.rs"], -} - -rust_test_host { - name: "serde_cbor_host_test_tests_ser", - defaults: ["serde_cbor_defaults_serde_cbor"], + name: "serde_cbor_test_tests_ser", + defaults: ["serde_cbor_test_defaults"], + host_supported: true, srcs: ["tests/ser.rs"], test_options: { unit_test: true, @@ -172,14 +129,9 @@ rust_test_host { } rust_test { - name: "serde_cbor_device_test_tests_ser", - defaults: ["serde_cbor_defaults_serde_cbor"], - srcs: ["tests/ser.rs"], -} - -rust_test_host { - name: "serde_cbor_host_test_tests_std_types", - defaults: ["serde_cbor_defaults_serde_cbor"], + name: "serde_cbor_test_tests_std_types", + defaults: ["serde_cbor_test_defaults"], + host_supported: true, srcs: ["tests/std_types.rs"], test_options: { unit_test: true, @@ -187,14 +139,9 @@ rust_test_host { } rust_test { - name: "serde_cbor_device_test_tests_std_types", - defaults: ["serde_cbor_defaults_serde_cbor"], - srcs: ["tests/std_types.rs"], -} - -rust_test_host { - name: "serde_cbor_host_test_tests_tags", - defaults: ["serde_cbor_defaults_serde_cbor"], + name: "serde_cbor_test_tests_tags", + defaults: ["serde_cbor_test_defaults"], + host_supported: true, srcs: ["tests/tags.rs"], test_options: { unit_test: true, @@ -202,31 +149,11 @@ rust_test_host { } rust_test { - name: "serde_cbor_device_test_tests_tags", - defaults: ["serde_cbor_defaults_serde_cbor"], - srcs: ["tests/tags.rs"], -} - -rust_test_host { - name: "serde_cbor_host_test_tests_value", - defaults: ["serde_cbor_defaults_serde_cbor"], + name: "serde_cbor_test_tests_value", + defaults: ["serde_cbor_test_defaults"], + host_supported: true, srcs: ["tests/value.rs"], test_options: { unit_test: true, }, } - -rust_test { - name: "serde_cbor_device_test_tests_value", - defaults: ["serde_cbor_defaults_serde_cbor"], - srcs: ["tests/value.rs"], -} - -// dependent_library ["feature_list"] -// half-1.7.1 -// proc-macro2-1.0.24 "default,proc-macro" -// quote-1.0.9 "default,proc-macro" -// serde-1.0.123 "std" -// serde_derive-1.0.123 -// syn-1.0.61 "clone-impls,default,derive,parsing,printing,proc-macro,quote" -// unicode-xid-0.2.1 "default" @@ -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 diff --git a/TEST_MAPPING b/TEST_MAPPING index 819a2f7..e3e6542 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,32 +1,105 @@ // Generated by update_crate_tests.py for tests that depend on this crate. { + "imports": [ + { + "path": "external/rust/crates/base64" + }, + { + "path": "external/rust/crates/tinytemplate" + }, + { + "path": "external/rust/crates/tinyvec" + }, + { + "path": "external/rust/crates/unicode-xid" + } + ], "presubmit": [ { - "name": "serde_cbor_device_test_tests_std_types" + "name": "diced_test" + }, + { + "name": "diced_vendor_test" + }, + { + "name": "keystore2_test" + }, + { + "name": "keystore2_test_utils_test" + }, + { + "name": "legacykeystore_test" + }, + { + "name": "microdroid_manager_test" + }, + { + "name": "serde_cbor_test_tests_bennofs" + }, + { + "name": "serde_cbor_test_tests_canonical" + }, + { + "name": "serde_cbor_test_tests_de" + }, + { + "name": "serde_cbor_test_tests_enum" + }, + { + "name": "serde_cbor_test_tests_ser" + }, + { + "name": "serde_cbor_test_tests_std_types" + }, + { + "name": "serde_cbor_test_tests_tags" + }, + { + "name": "serde_cbor_test_tests_value" + } + ], + "presubmit-rust": [ + { + "name": "diced_test" + }, + { + "name": "diced_vendor_test" + }, + { + "name": "keystore2_test" + }, + { + "name": "keystore2_test_utils_test" + }, + { + "name": "legacykeystore_test" + }, + { + "name": "microdroid_manager_test" }, { - "name": "serde_cbor_device_test_tests_bennofs" + "name": "serde_cbor_test_tests_bennofs" }, { - "name": "serde_cbor_device_test_src_lib" + "name": "serde_cbor_test_tests_canonical" }, { - "name": "serde_cbor_device_test_tests_enum" + "name": "serde_cbor_test_tests_de" }, { - "name": "serde_cbor_device_test_tests_tags" + "name": "serde_cbor_test_tests_enum" }, { - "name": "serde_cbor_device_test_tests_de" + "name": "serde_cbor_test_tests_ser" }, { - "name": "serde_cbor_device_test_tests_canonical" + "name": "serde_cbor_test_tests_std_types" }, { - "name": "serde_cbor_device_test_tests_value" + "name": "serde_cbor_test_tests_tags" }, { - "name": "serde_cbor_device_test_tests_ser" + "name": "serde_cbor_test_tests_value" } ] } diff --git a/cargo2android.json b/cargo2android.json new file mode 100644 index 0000000..604d595 --- /dev/null +++ b/cargo2android.json @@ -0,0 +1,7 @@ +{ + "device": true, + "features": "default,tags", + "run": true, + "tests": true, + "vendor-available": true +}
\ No newline at end of file @@ -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) } }; |