diff options
author | David Drysdale <drysdale@google.com> | 2024-01-25 14:06:49 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2024-01-25 14:06:49 +0000 |
commit | aff0b2297af681ed39dbe33e80d9d474f8058d53 (patch) | |
tree | 3d8776aada11273f6f10b575c730795489baca7e | |
parent | 7be86793408d040d492ab09b3bf219fe5c653850 (diff) | |
parent | 67127d028dcff46764497297390c92642c72ace8 (diff) | |
download | ciborium-main.tar.gz |
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/ciborium/+/2926739
Change-Id: Ic45515b90e661015ed8ab84e396a191943325681
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | .cargo_vcs_info.json | 7 | ||||
-rw-r--r-- | Android.bp | 4 | ||||
-rw-r--r-- | Cargo.toml | 10 | ||||
-rw-r--r-- | Cargo.toml.orig | 10 | ||||
-rw-r--r-- | METADATA | 23 | ||||
-rw-r--r-- | src/de/error.rs | 2 | ||||
-rw-r--r-- | src/de/mod.rs | 22 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/value/de.rs | 4 | ||||
-rw-r--r-- | src/value/ser.rs | 4 | ||||
-rw-r--r-- | tests/codec.rs | 7 |
11 files changed, 63 insertions, 32 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 4212810..f29a2d0 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,6 @@ { "git": { - "sha1": "7d8f6e499db51fe52f5d3c2ce1d0e0be61c7eaa2" - } -} + "sha1": "fdf3ec5c53256000f8e12f06c361ca18026a8d99" + }, + "path_in_vcs": "ciborium" +}
\ No newline at end of file @@ -23,7 +23,7 @@ rust_library { host_supported: true, crate_name: "ciborium", cargo_env_compat: true, - cargo_pkg_version: "0.2.1", + cargo_pkg_version: "0.2.2", srcs: ["src/lib.rs"], edition: "2021", features: [ @@ -47,7 +47,7 @@ rust_library_rlib { name: "libciborium_nostd", crate_name: "ciborium", cargo_env_compat: true, - cargo_pkg_version: "0.2.1", + cargo_pkg_version: "0.2.2", srcs: ["src/lib.rs"], edition: "2021", rustlibs: [ @@ -11,9 +11,9 @@ [package] edition = "2021" -rust-version = "1.56" +rust-version = "1.58" name = "ciborium" -version = "0.2.1" +version = "0.2.2" authors = ["Nathaniel McCallum <npmccallum@profian.com>"] description = "serde implementation of CBOR using ciborium-basic" homepage = "https://github.com/enarx/ciborium" @@ -25,14 +25,14 @@ repository = "https://github.com/enarx/ciborium" [package.metadata.docs.rs] all-features = true [dependencies.ciborium-io] -version = "0.2.1" +version = "0.2.2" features = ["alloc"] [dependencies.ciborium-ll] -version = "0.2.1" +version = "0.2.2" [dependencies.serde] -version = "1.0" +version = "1.0.100" features = ["alloc", "derive"] default-features = false [dev-dependencies.hex] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index d1e14d3..f13ee9f 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,10 +1,10 @@ [package] name = "ciborium" -version = "0.2.1" +version = "0.2.2" authors = ["Nathaniel McCallum <npmccallum@profian.com>"] license = "Apache-2.0" edition = "2021" -rust-version = "1.56" +rust-version = "1.58" homepage = "https://github.com/enarx/ciborium" repository = "https://github.com/enarx/ciborium" description = "serde implementation of CBOR using ciborium-basic" @@ -21,9 +21,9 @@ is-it-maintained-issue-resolution = { repository = "enarx/ciborium" } is-it-maintained-open-issues = { repository = "enarx/ciborium" } [dependencies] -ciborium-ll = { path = "../ciborium-ll", version = "0.2.1" } -ciborium-io = { path = "../ciborium-io", version = "0.2.1", features = ["alloc"] } -serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } +ciborium-ll = { path = "../ciborium-ll", version = "0.2.2" } +ciborium-io = { path = "../ciborium-io", version = "0.2.2", features = ["alloc"] } +serde = { version = "1.0.100", default-features = false, features = ["alloc", "derive"] } [dev-dependencies] serde_bytes = "0.11" @@ -1,23 +1,20 @@ # This project was upgraded with external_updater. # Usage: tools/external_updater/updater.sh update rust/crates/ciborium -# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md +# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md name: "ciborium" description: "serde implementation of CBOR using ciborium-basic" third_party { - url { - type: HOMEPAGE - value: "https://crates.io/crates/ciborium" - } - url { - type: ARCHIVE - value: "https://static.crates.io/crates/ciborium/ciborium-0.2.1.crate" - } - version: "0.2.1" license_type: NOTICE last_upgrade_date { - year: 2023 - month: 6 - day: 14 + year: 2024 + month: 1 + day: 24 + } + homepage: "https://crates.io/crates/ciborium" + identifier { + type: "Archive" + value: "https://static.crates.io/crates/ciborium/ciborium-0.2.2.crate" + version: "0.2.2" } } diff --git a/src/de/error.rs b/src/de/error.rs index 3334f81..996aab1 100644 --- a/src/de/error.rs +++ b/src/de/error.rs @@ -10,7 +10,7 @@ use serde::de::{Error as DeError, StdError}; pub enum Error<T> { /// An error occurred while reading bytes /// - /// Contains the underlying error reaturned while reading. + /// Contains the underlying error returned while reading. Io(T), /// An error occurred while parsing bytes diff --git a/src/de/mod.rs b/src/de/mod.rs index b68458d..1952a4b 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -815,17 +815,35 @@ where } } -/// Deserializes as CBOR from a type with [`impl ciborium_io::Read`](ciborium_io::Read) +/// Deserializes as CBOR from a type with [`impl +/// ciborium_io::Read`](ciborium_io::Read) using a 4KB buffer on the stack. +/// +/// If you want to deserialize faster at the cost of more memory, consider using +/// [`from_reader_with_buffer`](from_reader_with_buffer) with a larger buffer, +/// for example 64KB. #[inline] pub fn from_reader<T: de::DeserializeOwned, R: Read>(reader: R) -> Result<T, Error<R::Error>> where R::Error: core::fmt::Debug, { let mut scratch = [0; 4096]; + from_reader_with_buffer(reader, &mut scratch) +} +/// Deserializes as CBOR from a type with [`impl +/// ciborium_io::Read`](ciborium_io::Read), using a caller-specific buffer as a +/// temporary scratch space. +#[inline] +pub fn from_reader_with_buffer<T: de::DeserializeOwned, R: Read>( + reader: R, + scratch_buffer: &mut [u8], +) -> Result<T, Error<R::Error>> +where + R::Error: core::fmt::Debug, +{ let mut reader = Deserializer { decoder: reader.into(), - scratch: &mut scratch, + scratch: scratch_buffer, recurse: 256, }; @@ -100,6 +100,8 @@ pub mod value; // Re-export the [items recommended by serde](https://serde.rs/conventions.html). #[doc(inline)] pub use crate::de::from_reader; +#[doc(inline)] +pub use crate::de::from_reader_with_buffer; #[doc(inline)] pub use crate::ser::into_writer; diff --git a/src/value/de.rs b/src/value/de.rs index 6323190..38cfbec 100644 --- a/src/value/de.rs +++ b/src/value/de.rs @@ -499,6 +499,10 @@ impl<'a, 'de> de::Deserializer<'de> for Deserializer<&'a Value> { _ => Err(de::Error::invalid_type(self.0.into(), &"map")), } } + + fn is_human_readable(&self) -> bool { + false + } } impl<'a, 'de, T: Iterator<Item = &'a Value>> de::SeqAccess<'de> for Deserializer<T> { diff --git a/src/value/ser.rs b/src/value/ser.rs index a399719..3406d0b 100644 --- a/src/value/ser.rs +++ b/src/value/ser.rs @@ -268,6 +268,10 @@ impl ser::Serializer for Serializer<()> { tag: None, })) } + + fn is_human_readable(&self) -> bool { + false + } } impl ser::SerializeSeq for Serializer<Vec<Value>> { diff --git a/tests/codec.rs b/tests/codec.rs index d5df9a7..d737059 100644 --- a/tests/codec.rs +++ b/tests/codec.rs @@ -7,7 +7,7 @@ use std::convert::TryFrom; use std::fmt::Debug; use ciborium::value::Value; -use ciborium::{cbor, de::from_reader, ser::into_writer}; +use ciborium::{cbor, de::from_reader, de::from_reader_with_buffer, ser::into_writer}; use rstest::rstest; use serde::{de::DeserializeOwned, Deserialize, Serialize}; @@ -309,6 +309,11 @@ fn codec<'de, T: Serialize + Clone, V: Debug + PartialEq + DeserializeOwned, F: eprintln!("{:x?} == {:x?}", &value, &decoded); assert!(veq(&value, &decoded)); + let mut scratch = vec![0; 65536]; + let decoded: Value = from_reader_with_buffer(&bytes[..], &mut scratch).unwrap(); + eprintln!("{:x?} == {:x?}", &value, &decoded); + assert!(veq(&value, &decoded)); + let decoded: V = value.deserialized().unwrap(); let answer = equality(input); eprintln!("{:x?} == {:x?}", answer, decoded); |