diff -Nru rust-prost-0.12.6/benches/varint.rs rust-prost-0.13.5/benches/varint.rs --- rust-prost-0.12.6/benches/varint.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prost-0.13.5/benches/varint.rs 2006-07-24 01:21:28.000000000 +0000 @@ -2,7 +2,7 @@ use bytes::Buf; use criterion::{Criterion, Throughput}; -use prost::encoding::{decode_varint, encode_varint, encoded_len_varint}; +use prost::encoding::varint::{decode_varint, encode_varint, encoded_len_varint}; use rand::{rngs::StdRng, seq::SliceRandom, SeedableRng}; fn benchmark_varint(criterion: &mut Criterion, name: &str, mut values: Vec) { diff -Nru rust-prost-0.12.6/Cargo.toml rust-prost-0.13.5/Cargo.toml --- rust-prost-0.12.6/Cargo.toml 1970-01-01 00:00:01.000000000 +0000 +++ rust-prost-0.13.5/Cargo.toml 1970-01-01 00:00:01.000000000 +0000 @@ -11,17 +11,22 @@ [package] edition = "2021" -rust-version = "1.70" +rust-version = "1.71.1" name = "prost" -version = "0.12.6" +version = "0.13.5" authors = [ "Dan Burkert ", "Lucio Franco ", "Casper Meijn ", "Tokio Contributors ", ] +build = false +autolib = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = "A Protocol Buffers implementation for the Rust Language." -documentation = "https://docs.rs/prost" readme = "README.md" keywords = [ "protobuf", @@ -31,11 +36,24 @@ license = "Apache-2.0" repository = "https://github.com/tokio-rs/prost" +[features] +default = [ + "derive", + "std", +] +derive = ["dep:prost-derive"] +no-recursion-limit = [] +prost-derive = ["derive"] +std = [] + [lib] +name = "prost" +path = "src/lib.rs" bench = false [[bench]] name = "varint" +path = "benches/varint.rs" harness = false [dependencies.bytes] @@ -43,25 +61,15 @@ default-features = false [dependencies.prost-derive] -version = "0.12.6" +version = "0.13.5" optional = true [dev-dependencies.criterion] -version = "0.4" +version = "0.5" default-features = false [dev-dependencies.proptest] version = "1" [dev-dependencies.rand] -version = "0.8" - -[features] -default = [ - "derive", - "std", -] -derive = ["dep:prost-derive"] -no-recursion-limit = [] -prost-derive = ["derive"] -std = [] +version = "0.9" diff -Nru rust-prost-0.12.6/Cargo.toml.orig rust-prost-0.13.5/Cargo.toml.orig --- rust-prost-0.12.6/Cargo.toml.orig 2006-07-24 01:21:28.000000000 +0000 +++ rust-prost-0.13.5/Cargo.toml.orig 2006-07-24 01:21:28.000000000 +0000 @@ -1,21 +1,15 @@ [package] name = "prost" -version = "0.12.6" -authors = [ - "Dan Burkert ", - "Lucio Franco ", - "Casper Meijn ", - "Tokio Contributors ", -] -license = "Apache-2.0" -repository = "https://github.com/tokio-rs/prost" -documentation = "https://docs.rs/prost" readme = "README.md" description = "A Protocol Buffers implementation for the Rust Language." keywords = ["protobuf", "serialization"] categories = ["encoding"] -edition = "2021" -rust-version = "1.70" +version.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +edition.workspace = true +rust-version.workspace = true [lib] # https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options @@ -30,12 +24,12 @@ [dependencies] bytes = { version = "1", default-features = false } -prost-derive = { version = "0.12.6", path = "../prost-derive", optional = true } +prost-derive = { version = "0.13.5", path = "../prost-derive", optional = true } [dev-dependencies] -criterion = { version = "0.4", default-features = false } +criterion = { version = "0.5", default-features = false } proptest = "1" -rand = "0.8" +rand = "0.9" [[bench]] name = "varint" diff -Nru rust-prost-0.12.6/.cargo_vcs_info.json rust-prost-0.13.5/.cargo_vcs_info.json --- rust-prost-0.12.6/.cargo_vcs_info.json 1970-01-01 00:00:01.000000000 +0000 +++ rust-prost-0.13.5/.cargo_vcs_info.json 1970-01-01 00:00:01.000000000 +0000 @@ -1,6 +1,6 @@ { "git": { - "sha1": "d42c85e790263f78f6c626ceb0dac5fda0edcb41" + "sha1": "d505b184e933e1f9ff5679106ffc51b7e3c2755e" }, "path_in_vcs": "prost" } \ No newline at end of file diff -Nru rust-prost-0.12.6/debian/changelog rust-prost-0.13.5/debian/changelog --- rust-prost-0.12.6/debian/changelog 2024-07-05 12:48:21.000000000 +0000 +++ rust-prost-0.13.5/debian/changelog 2025-04-10 11:44:43.000000000 +0000 @@ -1,3 +1,10 @@ +rust-prost (0.13.5-1) UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; urgency=medium + + * Team upload. + * Package prost 0.13.5 from crates.io using debcargo 2.7.8 + + -- Blair Noctis Thu, 10 Apr 2025 11:44:43 +0000 + rust-prost (0.12.6-1) unstable; urgency=medium * Team upload. diff -Nru rust-prost-0.12.6/debian/compat rust-prost-0.13.5/debian/compat --- rust-prost-0.12.6/debian/compat 2024-07-05 12:48:21.000000000 +0000 +++ rust-prost-0.13.5/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -12 diff -Nru rust-prost-0.12.6/debian/control rust-prost-0.13.5/debian/control --- rust-prost-0.12.6/debian/control 2024-07-05 12:48:21.000000000 +0000 +++ rust-prost-0.13.5/debian/control 2025-04-10 11:44:43.000000000 +0000 @@ -1,19 +1,20 @@ Source: rust-prost Section: rust Priority: optional -Build-Depends: debhelper (>= 12), - dh-cargo (>= 25), - cargo:native , - rustc:native (>= 1.70) , +Build-Depends: debhelper-compat (= 13), + dh-sequence-cargo +Build-Depends-Arch: cargo:native , + rustc:native (>= 1.71.1) , libstd-rust-dev , librust-bytes-1-dev , - librust-prost-derive-0.12+default-dev (>= 0.12.6-~~) + librust-prost-derive-0.13+default-dev (>= 0.13.5-~~) Maintainer: Debian Rust Maintainers Uploaders: Emanuele Rocca -Standards-Version: 4.6.2 +Standards-Version: 4.7.0 Vcs-Git: https://salsa.debian.org/rust-team/debcargo-conf.git [src/prost] Vcs-Browser: https://salsa.debian.org/rust-team/debcargo-conf/tree/master/src/prost +Homepage: https://github.com/tokio-rs/prost X-Cargo-Crate: prost Rules-Requires-Root: no @@ -23,7 +24,7 @@ Depends: ${misc:Depends}, librust-bytes-1-dev, - librust-prost-derive-0.12+default-dev (>= 0.12.6-~~) + librust-prost-derive-0.13+default-dev (>= 0.13.5-~~) Provides: librust-prost+default-dev (= ${binary:Version}), librust-prost+derive-dev (= ${binary:Version}), @@ -36,17 +37,17 @@ librust-prost-0+no-recursion-limit-dev (= ${binary:Version}), librust-prost-0+prost-derive-dev (= ${binary:Version}), librust-prost-0+std-dev (= ${binary:Version}), - librust-prost-0.12-dev (= ${binary:Version}), - librust-prost-0.12+default-dev (= ${binary:Version}), - librust-prost-0.12+derive-dev (= ${binary:Version}), - librust-prost-0.12+no-recursion-limit-dev (= ${binary:Version}), - librust-prost-0.12+prost-derive-dev (= ${binary:Version}), - librust-prost-0.12+std-dev (= ${binary:Version}), - librust-prost-0.12.6-dev (= ${binary:Version}), - librust-prost-0.12.6+default-dev (= ${binary:Version}), - librust-prost-0.12.6+derive-dev (= ${binary:Version}), - librust-prost-0.12.6+no-recursion-limit-dev (= ${binary:Version}), - librust-prost-0.12.6+prost-derive-dev (= ${binary:Version}), - librust-prost-0.12.6+std-dev (= ${binary:Version}) + librust-prost-0.13-dev (= ${binary:Version}), + librust-prost-0.13+default-dev (= ${binary:Version}), + librust-prost-0.13+derive-dev (= ${binary:Version}), + librust-prost-0.13+no-recursion-limit-dev (= ${binary:Version}), + librust-prost-0.13+prost-derive-dev (= ${binary:Version}), + librust-prost-0.13+std-dev (= ${binary:Version}), + librust-prost-0.13.5-dev (= ${binary:Version}), + librust-prost-0.13.5+default-dev (= ${binary:Version}), + librust-prost-0.13.5+derive-dev (= ${binary:Version}), + librust-prost-0.13.5+no-recursion-limit-dev (= ${binary:Version}), + librust-prost-0.13.5+prost-derive-dev (= ${binary:Version}), + librust-prost-0.13.5+std-dev (= ${binary:Version}) Description: Protocol Buffers implementation for the Rust Language - Rust source code Source code for Debianized Rust crate "prost" diff -Nru rust-prost-0.12.6/debian/copyright.debcargo.hint rust-prost-0.13.5/debian/copyright.debcargo.hint --- rust-prost-0.12.6/debian/copyright.debcargo.hint 2024-07-05 12:48:21.000000000 +0000 +++ rust-prost-0.13.5/debian/copyright.debcargo.hint 2025-04-10 11:44:43.000000000 +0000 @@ -29,8 +29,8 @@ Files: debian/* Copyright: - 2023-2024 Debian Rust Maintainers - 2023-2024 Emanuele Rocca + 2023-2025 Debian Rust Maintainers + 2023-2025 Emanuele Rocca License: Apache-2.0 License: Apache-2.0 diff -Nru rust-prost-0.12.6/debian/patches/fix-feature-gates.patch rust-prost-0.13.5/debian/patches/fix-feature-gates.patch --- rust-prost-0.12.6/debian/patches/fix-feature-gates.patch 1970-01-01 00:00:00.000000000 +0000 +++ rust-prost-0.13.5/debian/patches/fix-feature-gates.patch 2025-04-10 11:44:43.000000000 +0000 @@ -0,0 +1,15 @@ +Last-Update: 2025-04-10 +--- a/src/encoding/varint.rs ++++ b/src/encoding/varint.rs +@@ -180,3 +180,3 @@ + #[test] +- fn varint() { ++ #[cfg(feature = "std")] fn varint() { + fn check(value: u64, encoded: &[u8]) { +--- a/src/error.rs ++++ b/src/error.rs +@@ -161,3 +161,3 @@ + +- assert_eq!( ++ #[cfg(feature = "std")] assert_eq!( + decode_error.to_string(), diff -Nru rust-prost-0.12.6/debian/patches/no-benches.patch rust-prost-0.13.5/debian/patches/no-benches.patch --- rust-prost-0.12.6/debian/patches/no-benches.patch 1970-01-01 00:00:00.000000000 +0000 +++ rust-prost-0.13.5/debian/patches/no-benches.patch 2025-04-10 11:44:43.000000000 +0000 @@ -0,0 +1,14 @@ +Forwarded: not-needed +Last-Update: 2025-04-10 +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -53,3 +53,3 @@ + +-[[bench]] ++[[disabled.bench]] + name = "varint" +@@ -66,3 +66,3 @@ + +-[dev-dependencies.criterion] ++[disabled.dev-dependencies.criterion] + version = "0.5" diff -Nru rust-prost-0.12.6/debian/patches/no-fuzz.patch rust-prost-0.13.5/debian/patches/no-fuzz.patch --- rust-prost-0.12.6/debian/patches/no-fuzz.patch 1970-01-01 00:00:00.000000000 +0000 +++ rust-prost-0.13.5/debian/patches/no-fuzz.patch 2025-04-10 11:44:43.000000000 +0000 @@ -0,0 +1,63 @@ +Forwarded: not-needed +Last-Update: 2025-04-10 +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -71 +71 @@ +-[dev-dependencies.proptest] ++[disabled.dev-dependencies.proptest] +--- a/src/encoding.rs ++++ b/src/encoding.rs +@@ -319 +319 @@ +- use proptest::prelude::*; ++ //use proptest::prelude::*; +@@ -322 +322 @@ +- use crate::encoding::test::{ ++ #[cfg(any())] use crate::encoding::test::{ +@@ -327 +327 @@ +- proptest! { ++ #[cfg(any())] proptest! { +@@ -445 +445 @@ +- use proptest::prelude::*; ++ //use proptest::prelude::*; +@@ -447 +447 @@ +- use super::super::test::{check_collection_type, check_type}; ++ //use super::super::test::{check_collection_type, check_type}; +@@ -450 +450 @@ +- proptest! { ++ #[cfg(any())] proptest! { +@@ -612 +612 @@ +- use proptest::prelude::*; ++ //use proptest::prelude::*; +@@ -614 +614 @@ +- use super::super::test::{check_collection_type, check_type}; ++ //use super::super::test::{check_collection_type, check_type}; +@@ -617 +617 @@ +- proptest! { ++ #[cfg(any())] proptest! { +@@ -747 +747 @@ +- use proptest::prelude::*; ++ //use proptest::prelude::*; +@@ -749 +749 @@ +- use super::super::test::{check_collection_type, check_type}; ++ //use super::super::test::{check_collection_type, check_type}; +@@ -752 +752 @@ +- proptest! { ++ #[cfg(any())] proptest! { +@@ -1153 +1153 @@ +- use proptest::{prelude::*, test_runner::TestCaseResult}; ++ //use proptest::{prelude::*, test_runner::TestCaseResult}; +@@ -1157 +1157 @@ +- pub fn check_type( ++ #[cfg(any())] pub fn check_type( +@@ -1243 +1243 @@ +- pub fn check_collection_type( ++ #[cfg(any())] pub fn check_collection_type( +@@ -1348 +1348 @@ +- use proptest::prelude::*; ++ //use proptest::prelude::*; +@@ -1351 +1351 @@ +- use crate::encoding::test::check_collection_type; ++ //use crate::encoding::test::check_collection_type; +@@ -1363 +1363 @@ +- proptest! { ++ #[cfg(any())] proptest! { diff -Nru rust-prost-0.12.6/debian/patches/relax-deps.patch rust-prost-0.13.5/debian/patches/relax-deps.patch --- rust-prost-0.12.6/debian/patches/relax-deps.patch 2024-07-05 12:48:21.000000000 +0000 +++ rust-prost-0.13.5/debian/patches/relax-deps.patch 2025-04-10 11:44:43.000000000 +0000 @@ -1,13 +1,8 @@ -Index: prost/Cargo.toml -=================================================================== ---- prost.orig/Cargo.toml -+++ prost/Cargo.toml -@@ -47,7 +47,7 @@ version = "0.12.6" - optional = true - - [dev-dependencies.criterion] --version = "0.4" -+version = "0.5" - default-features = false - - [dev-dependencies.proptest] +Forwarded: not-needed +Last-Update: 2025-04-10 +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -74,2 +74,2 @@ + [dev-dependencies.rand] +-version = "0.9" ++version = "0.8" diff -Nru rust-prost-0.12.6/debian/patches/series rust-prost-0.13.5/debian/patches/series --- rust-prost-0.12.6/debian/patches/series 2024-07-05 12:48:21.000000000 +0000 +++ rust-prost-0.13.5/debian/patches/series 2025-04-10 11:44:43.000000000 +0000 @@ -1 +1,4 @@ +no-benches.patch +no-fuzz.patch relax-deps.patch +fix-feature-gates.patch diff -Nru rust-prost-0.12.6/debian/tests/control rust-prost-0.13.5/debian/tests/control --- rust-prost-0.12.6/debian/tests/control 2024-07-05 12:48:21.000000000 +0000 +++ rust-prost-0.13.5/debian/tests/control 2025-04-10 11:44:43.000000000 +0000 @@ -1,34 +1,34 @@ -Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.12.6 --all-targets --all-features +Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.13.5 --all-targets --all-features Features: test-name=rust-prost:@ -Depends: dh-cargo (>= 18), librust-criterion-0.5-dev, librust-proptest-1+default-dev, librust-rand-0.8+default-dev, @ +Depends: dh-cargo (>= 31), rustc (>= 1.71.1), librust-rand-0.8+default-dev, @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.12.6 --all-targets +Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.13.5 --all-targets Features: test-name=librust-prost-dev:default -Depends: dh-cargo (>= 18), librust-criterion-0.5-dev, librust-proptest-1+default-dev, librust-rand-0.8+default-dev, @ +Depends: dh-cargo (>= 31), rustc (>= 1.71.1), librust-rand-0.8+default-dev, @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.12.6 --all-targets --no-default-features --features derive +Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.13.5 --all-targets --no-default-features --features derive Features: test-name=librust-prost-dev:derive -Depends: dh-cargo (>= 18), librust-criterion-0.5-dev, librust-proptest-1+default-dev, librust-rand-0.8+default-dev, @ +Depends: dh-cargo (>= 31), rustc (>= 1.71.1), librust-rand-0.8+default-dev, @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.12.6 --all-targets --no-default-features --features no-recursion-limit +Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.13.5 --all-targets --no-default-features --features no-recursion-limit Features: test-name=librust-prost-dev:no-recursion-limit -Depends: dh-cargo (>= 18), librust-criterion-0.5-dev, librust-proptest-1+default-dev, librust-rand-0.8+default-dev, @ +Depends: dh-cargo (>= 31), rustc (>= 1.71.1), librust-rand-0.8+default-dev, @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.12.6 --all-targets --no-default-features --features prost-derive +Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.13.5 --all-targets --no-default-features --features prost-derive Features: test-name=librust-prost-dev:prost-derive -Depends: dh-cargo (>= 18), librust-criterion-0.5-dev, librust-proptest-1+default-dev, librust-rand-0.8+default-dev, @ +Depends: dh-cargo (>= 31), rustc (>= 1.71.1), librust-rand-0.8+default-dev, @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.12.6 --all-targets --no-default-features --features std +Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.13.5 --all-targets --no-default-features --features std Features: test-name=librust-prost-dev:std -Depends: dh-cargo (>= 18), librust-criterion-0.5-dev, librust-proptest-1+default-dev, librust-rand-0.8+default-dev, @ +Depends: dh-cargo (>= 31), rustc (>= 1.71.1), librust-rand-0.8+default-dev, @ Restrictions: allow-stderr, skip-not-installable -Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.12.6 --all-targets --no-default-features +Test-Command: /usr/share/cargo/bin/cargo-auto-test prost 0.13.5 --all-targets --no-default-features Features: test-name=librust-prost-dev: -Depends: dh-cargo (>= 18), librust-criterion-0.5-dev, librust-proptest-1+default-dev, librust-rand-0.8+default-dev, @ +Depends: dh-cargo (>= 31), rustc (>= 1.71.1), librust-rand-0.8+default-dev, @ Restrictions: allow-stderr, skip-not-installable diff -Nru rust-prost-0.12.6/debian/watch rust-prost-0.13.5/debian/watch --- rust-prost-0.12.6/debian/watch 2024-07-05 12:48:21.000000000 +0000 +++ rust-prost-0.13.5/debian/watch 2025-04-10 11:44:43.000000000 +0000 @@ -1,4 +1,4 @@ version=4 opts=filenamemangle=s/.*\/(.*)\/download/prost-$1\.tar\.gz/g,\ -uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha)\d*)$/$1~$2/ \ +uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha)\.?\d*)$/$1~$2/ \ https://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=crates.io/prost .*/crates/prost/@ANY_VERSION@/download diff -Nru rust-prost-0.12.6/LICENSE rust-prost-0.13.5/LICENSE --- rust-prost-0.12.6/LICENSE 1970-01-01 00:00:00.000000000 +0000 +++ rust-prost-0.13.5/LICENSE 2006-07-24 01:21:28.000000000 +0000 @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff -Nru rust-prost-0.12.6/README.md rust-prost-0.13.5/README.md --- rust-prost-0.12.6/README.md 2006-07-24 01:21:28.000000000 +0000 +++ rust-prost-0.13.5/README.md 2006-07-24 01:21:28.000000000 +0000 @@ -30,9 +30,9 @@ ```ignore [dependencies] -prost = "0.12" +prost = "0.13" # Only necessary if using Protobuf well-known types: -prost-types = "0.12" +prost-types = "0.13" ``` The recommended way to add `.proto` compilation to a Cargo project is to use the @@ -380,9 +380,9 @@ ```ignore [dependencies] -prost = { version = "0.6", default-features = false, features = ["prost-derive"] } +prost = { version = "0.13.5", default-features = false, features = ["prost-derive"] } # Only necessary if using Protobuf well-known types: -prost-types = { version = "0.6", default-features = false } +prost-types = { version = "0.13.5", default-features = false } ``` Additionally, configure `prost-build` to output `BTreeMap`s instead of `HashMap`s diff -Nru rust-prost-0.12.6/src/encoding/length_delimiter.rs rust-prost-0.13.5/src/encoding/length_delimiter.rs --- rust-prost-0.12.6/src/encoding/length_delimiter.rs 1970-01-01 00:00:00.000000000 +0000 +++ rust-prost-0.13.5/src/encoding/length_delimiter.rs 2006-07-24 01:21:28.000000000 +0000 @@ -0,0 +1,53 @@ +pub use crate::error::{DecodeError, EncodeError, UnknownEnumValue}; +pub use crate::message::Message; +pub use crate::name::Name; + +use bytes::{Buf, BufMut}; + +use crate::encoding::varint::{decode_varint, encode_varint, encoded_len_varint}; + +/// Encodes a length delimiter to the buffer. +/// +/// See [Message.encode_length_delimited] for more info. +/// +/// An error will be returned if the buffer does not have sufficient capacity to encode the +/// delimiter. +pub fn encode_length_delimiter(length: usize, buf: &mut impl BufMut) -> Result<(), EncodeError> { + let length = length as u64; + let required = encoded_len_varint(length); + let remaining = buf.remaining_mut(); + if required > remaining { + return Err(EncodeError::new(required, remaining)); + } + encode_varint(length, buf); + Ok(()) +} + +/// Returns the encoded length of a length delimiter. +/// +/// Applications may use this method to ensure sufficient buffer capacity before calling +/// `encode_length_delimiter`. The returned size will be between 1 and 10, inclusive. +pub fn length_delimiter_len(length: usize) -> usize { + encoded_len_varint(length as u64) +} + +/// Decodes a length delimiter from the buffer. +/// +/// This method allows the length delimiter to be decoded independently of the message, when the +/// message is encoded with [Message.encode_length_delimited]. +/// +/// An error may be returned in two cases: +/// +/// * If the supplied buffer contains fewer than 10 bytes, then an error indicates that more +/// input is required to decode the full delimiter. +/// * If the supplied buffer contains 10 bytes or more, then the buffer contains an invalid +/// delimiter, and typically the buffer should be considered corrupt. +pub fn decode_length_delimiter(mut buf: impl Buf) -> Result { + let length = decode_varint(&mut buf)?; + if length > usize::MAX as u64 { + return Err(DecodeError::new( + "length delimiter exceeds maximum usize value", + )); + } + Ok(length as usize) +} diff -Nru rust-prost-0.12.6/src/encoding/varint.rs rust-prost-0.13.5/src/encoding/varint.rs --- rust-prost-0.12.6/src/encoding/varint.rs 1970-01-01 00:00:00.000000000 +0000 +++ rust-prost-0.13.5/src/encoding/varint.rs 2006-07-24 01:21:28.000000000 +0000 @@ -0,0 +1,274 @@ +use core::cmp::min; +use core::num::NonZeroU64; + +use ::bytes::{Buf, BufMut}; + +use crate::DecodeError; + +/// Encodes an integer value into LEB128 variable length format, and writes it to the buffer. +/// The buffer must have enough remaining space (maximum 10 bytes). +#[inline] +pub fn encode_varint(mut value: u64, buf: &mut impl BufMut) { + // Varints are never more than 10 bytes + for _ in 0..10 { + if value < 0x80 { + buf.put_u8(value as u8); + break; + } else { + buf.put_u8(((value & 0x7F) | 0x80) as u8); + value >>= 7; + } + } +} + +/// Returns the encoded length of the value in LEB128 variable length format. +/// The returned value will be between 1 and 10, inclusive. +#[inline] +pub const fn encoded_len_varint(value: u64) -> usize { + // Based on [VarintSize64][1]. + // [1]: https://github.com/protocolbuffers/protobuf/blob/v28.3/src/google/protobuf/io/coded_stream.h#L1744-L1756 + // Safety: value | 1 is non-zero. + let log2value = unsafe { NonZeroU64::new_unchecked(value | 1) }.ilog2(); + ((log2value * 9 + (64 + 9)) / 64) as usize +} + +/// Decodes a LEB128-encoded variable length integer from the buffer. +#[inline] +pub fn decode_varint(buf: &mut impl Buf) -> Result { + let bytes = buf.chunk(); + let len = bytes.len(); + if len == 0 { + return Err(DecodeError::new("invalid varint")); + } + + let byte = bytes[0]; + if byte < 0x80 { + buf.advance(1); + Ok(u64::from(byte)) + } else if len > 10 || bytes[len - 1] < 0x80 { + let (value, advance) = decode_varint_slice(bytes)?; + buf.advance(advance); + Ok(value) + } else { + decode_varint_slow(buf) + } +} + +/// Decodes a LEB128-encoded variable length integer from the slice, returning the value and the +/// number of bytes read. +/// +/// Based loosely on [`ReadVarint64FromArray`][1] with a varint overflow check from +/// [`ConsumeVarint`][2]. +/// +/// ## Safety +/// +/// The caller must ensure that `bytes` is non-empty and either `bytes.len() >= 10` or the last +/// element in bytes is < `0x80`. +/// +/// [1]: https://github.com/google/protobuf/blob/3.3.x/src/google/protobuf/io/coded_stream.cc#L365-L406 +/// [2]: https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/encoding/protowire/wire.go#L358 +#[inline] +fn decode_varint_slice(bytes: &[u8]) -> Result<(u64, usize), DecodeError> { + // Fully unrolled varint decoding loop. Splitting into 32-bit pieces gives better performance. + + // Use assertions to ensure memory safety, but it should always be optimized after inline. + assert!(!bytes.is_empty()); + assert!(bytes.len() > 10 || bytes[bytes.len() - 1] < 0x80); + + let mut b: u8 = unsafe { *bytes.get_unchecked(0) }; + let mut part0: u32 = u32::from(b); + if b < 0x80 { + return Ok((u64::from(part0), 1)); + }; + part0 -= 0x80; + b = unsafe { *bytes.get_unchecked(1) }; + part0 += u32::from(b) << 7; + if b < 0x80 { + return Ok((u64::from(part0), 2)); + }; + part0 -= 0x80 << 7; + b = unsafe { *bytes.get_unchecked(2) }; + part0 += u32::from(b) << 14; + if b < 0x80 { + return Ok((u64::from(part0), 3)); + }; + part0 -= 0x80 << 14; + b = unsafe { *bytes.get_unchecked(3) }; + part0 += u32::from(b) << 21; + if b < 0x80 { + return Ok((u64::from(part0), 4)); + }; + part0 -= 0x80 << 21; + let value = u64::from(part0); + + b = unsafe { *bytes.get_unchecked(4) }; + let mut part1: u32 = u32::from(b); + if b < 0x80 { + return Ok((value + (u64::from(part1) << 28), 5)); + }; + part1 -= 0x80; + b = unsafe { *bytes.get_unchecked(5) }; + part1 += u32::from(b) << 7; + if b < 0x80 { + return Ok((value + (u64::from(part1) << 28), 6)); + }; + part1 -= 0x80 << 7; + b = unsafe { *bytes.get_unchecked(6) }; + part1 += u32::from(b) << 14; + if b < 0x80 { + return Ok((value + (u64::from(part1) << 28), 7)); + }; + part1 -= 0x80 << 14; + b = unsafe { *bytes.get_unchecked(7) }; + part1 += u32::from(b) << 21; + if b < 0x80 { + return Ok((value + (u64::from(part1) << 28), 8)); + }; + part1 -= 0x80 << 21; + let value = value + ((u64::from(part1)) << 28); + + b = unsafe { *bytes.get_unchecked(8) }; + let mut part2: u32 = u32::from(b); + if b < 0x80 { + return Ok((value + (u64::from(part2) << 56), 9)); + }; + part2 -= 0x80; + b = unsafe { *bytes.get_unchecked(9) }; + part2 += u32::from(b) << 7; + // Check for u64::MAX overflow. See [`ConsumeVarint`][1] for details. + // [1]: https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/encoding/protowire/wire.go#L358 + if b < 0x02 { + return Ok((value + (u64::from(part2) << 56), 10)); + }; + + // We have overrun the maximum size of a varint (10 bytes) or the final byte caused an overflow. + // Assume the data is corrupt. + Err(DecodeError::new("invalid varint")) +} + +/// Decodes a LEB128-encoded variable length integer from the buffer, advancing the buffer as +/// necessary. +/// +/// Contains a varint overflow check from [`ConsumeVarint`][1]. +/// +/// [1]: https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/encoding/protowire/wire.go#L358 +#[inline(never)] +#[cold] +fn decode_varint_slow(buf: &mut impl Buf) -> Result { + let mut value = 0; + for count in 0..min(10, buf.remaining()) { + let byte = buf.get_u8(); + value |= u64::from(byte & 0x7F) << (count * 7); + if byte <= 0x7F { + // Check for u64::MAX overflow. See [`ConsumeVarint`][1] for details. + // [1]: https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/encoding/protowire/wire.go#L358 + if count == 9 && byte >= 0x02 { + return Err(DecodeError::new("invalid varint")); + } else { + return Ok(value); + } + } + } + + Err(DecodeError::new("invalid varint")) +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn varint() { + fn check(value: u64, encoded: &[u8]) { + // Small buffer. + let mut buf = Vec::with_capacity(1); + encode_varint(value, &mut buf); + assert_eq!(buf, encoded); + + // Large buffer. + let mut buf = Vec::with_capacity(100); + encode_varint(value, &mut buf); + assert_eq!(buf, encoded); + + assert_eq!(encoded_len_varint(value), encoded.len()); + + // See: https://github.com/tokio-rs/prost/pull/1008 for copying reasoning. + let mut encoded_copy = encoded; + let roundtrip_value = decode_varint(&mut encoded_copy).expect("decoding failed"); + assert_eq!(value, roundtrip_value); + + let mut encoded_copy = encoded; + let roundtrip_value = + decode_varint_slow(&mut encoded_copy).expect("slow decoding failed"); + assert_eq!(value, roundtrip_value); + } + + check(2u64.pow(0) - 1, &[0x00]); + check(2u64.pow(0), &[0x01]); + + check(2u64.pow(7) - 1, &[0x7F]); + check(2u64.pow(7), &[0x80, 0x01]); + check(300, &[0xAC, 0x02]); + + check(2u64.pow(14) - 1, &[0xFF, 0x7F]); + check(2u64.pow(14), &[0x80, 0x80, 0x01]); + + check(2u64.pow(21) - 1, &[0xFF, 0xFF, 0x7F]); + check(2u64.pow(21), &[0x80, 0x80, 0x80, 0x01]); + + check(2u64.pow(28) - 1, &[0xFF, 0xFF, 0xFF, 0x7F]); + check(2u64.pow(28), &[0x80, 0x80, 0x80, 0x80, 0x01]); + + check(2u64.pow(35) - 1, &[0xFF, 0xFF, 0xFF, 0xFF, 0x7F]); + check(2u64.pow(35), &[0x80, 0x80, 0x80, 0x80, 0x80, 0x01]); + + check(2u64.pow(42) - 1, &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F]); + check(2u64.pow(42), &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01]); + + check( + 2u64.pow(49) - 1, + &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], + ); + check( + 2u64.pow(49), + &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01], + ); + + check( + 2u64.pow(56) - 1, + &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], + ); + check( + 2u64.pow(56), + &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01], + ); + + check( + 2u64.pow(63) - 1, + &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], + ); + check( + 2u64.pow(63), + &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01], + ); + + check( + u64::MAX, + &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01], + ); + } + + const U64_MAX_PLUS_ONE: &[u8] = &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x02]; + + #[test] + fn varint_overflow() { + let mut copy = U64_MAX_PLUS_ONE; + decode_varint(&mut copy).expect_err("decoding u64::MAX + 1 succeeded"); + } + + #[test] + fn variant_slow_overflow() { + let mut copy = U64_MAX_PLUS_ONE; + decode_varint_slow(&mut copy).expect_err("slow decoding u64::MAX + 1 succeeded"); + } +} diff -Nru rust-prost-0.12.6/src/encoding/wire_type.rs rust-prost-0.13.5/src/encoding/wire_type.rs --- rust-prost-0.12.6/src/encoding/wire_type.rs 1970-01-01 00:00:00.000000000 +0000 +++ rust-prost-0.13.5/src/encoding/wire_type.rs 2006-07-24 01:21:28.000000000 +0000 @@ -0,0 +1,49 @@ +use crate::DecodeError; +use alloc::format; + +/// Represent the wire type for protobuf encoding. +/// +/// The integer value is equvilant with the encoded value. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(u8)] +pub enum WireType { + Varint = 0, + SixtyFourBit = 1, + LengthDelimited = 2, + StartGroup = 3, + EndGroup = 4, + ThirtyTwoBit = 5, +} + +impl TryFrom for WireType { + type Error = DecodeError; + + #[inline] + fn try_from(value: u64) -> Result { + match value { + 0 => Ok(WireType::Varint), + 1 => Ok(WireType::SixtyFourBit), + 2 => Ok(WireType::LengthDelimited), + 3 => Ok(WireType::StartGroup), + 4 => Ok(WireType::EndGroup), + 5 => Ok(WireType::ThirtyTwoBit), + _ => Err(DecodeError::new(format!( + "invalid wire type value: {}", + value + ))), + } + } +} + +/// Checks that the expected wire type matches the actual wire type, +/// or returns an error result. +#[inline] +pub fn check_wire_type(expected: WireType, actual: WireType) -> Result<(), DecodeError> { + if expected != actual { + return Err(DecodeError::new(format!( + "invalid wire type: {:?} (expected {:?})", + actual, expected + ))); + } + Ok(()) +} diff -Nru rust-prost-0.12.6/src/encoding.rs rust-prost-0.13.5/src/encoding.rs --- rust-prost-0.12.6/src/encoding.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prost-0.13.5/src/encoding.rs 2006-07-24 01:21:28.000000000 +0000 @@ -8,182 +8,24 @@ use alloc::format; use alloc::string::String; use alloc::vec::Vec; -use core::cmp::min; use core::mem; use core::str; -use core::u32; -use core::usize; use ::bytes::{Buf, BufMut, Bytes}; use crate::DecodeError; use crate::Message; -/// Encodes an integer value into LEB128 variable length format, and writes it to the buffer. -/// The buffer must have enough remaining space (maximum 10 bytes). -#[inline] -pub fn encode_varint(mut value: u64, buf: &mut B) -where - B: BufMut, -{ - // Varints are never more than 10 bytes - for _ in 0..10 { - if value < 0x80 { - buf.put_u8(value as u8); - break; - } else { - buf.put_u8(((value & 0x7F) | 0x80) as u8); - value >>= 7; - } - } -} - -/// Decodes a LEB128-encoded variable length integer from the buffer. -#[inline] -pub fn decode_varint(buf: &mut B) -> Result -where - B: Buf, -{ - let bytes = buf.chunk(); - let len = bytes.len(); - if len == 0 { - return Err(DecodeError::new("invalid varint")); - } - - let byte = bytes[0]; - if byte < 0x80 { - buf.advance(1); - Ok(u64::from(byte)) - } else if len > 10 || bytes[len - 1] < 0x80 { - let (value, advance) = decode_varint_slice(bytes)?; - buf.advance(advance); - Ok(value) - } else { - decode_varint_slow(buf) - } -} - -/// Decodes a LEB128-encoded variable length integer from the slice, returning the value and the -/// number of bytes read. -/// -/// Based loosely on [`ReadVarint64FromArray`][1] with a varint overflow check from -/// [`ConsumeVarint`][2]. -/// -/// ## Safety -/// -/// The caller must ensure that `bytes` is non-empty and either `bytes.len() >= 10` or the last -/// element in bytes is < `0x80`. -/// -/// [1]: https://github.com/google/protobuf/blob/3.3.x/src/google/protobuf/io/coded_stream.cc#L365-L406 -/// [2]: https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/encoding/protowire/wire.go#L358 -#[inline] -fn decode_varint_slice(bytes: &[u8]) -> Result<(u64, usize), DecodeError> { - // Fully unrolled varint decoding loop. Splitting into 32-bit pieces gives better performance. +pub mod varint; +pub use varint::{decode_varint, encode_varint, encoded_len_varint}; - // Use assertions to ensure memory safety, but it should always be optimized after inline. - assert!(!bytes.is_empty()); - assert!(bytes.len() > 10 || bytes[bytes.len() - 1] < 0x80); - - let mut b: u8 = unsafe { *bytes.get_unchecked(0) }; - let mut part0: u32 = u32::from(b); - if b < 0x80 { - return Ok((u64::from(part0), 1)); - }; - part0 -= 0x80; - b = unsafe { *bytes.get_unchecked(1) }; - part0 += u32::from(b) << 7; - if b < 0x80 { - return Ok((u64::from(part0), 2)); - }; - part0 -= 0x80 << 7; - b = unsafe { *bytes.get_unchecked(2) }; - part0 += u32::from(b) << 14; - if b < 0x80 { - return Ok((u64::from(part0), 3)); - }; - part0 -= 0x80 << 14; - b = unsafe { *bytes.get_unchecked(3) }; - part0 += u32::from(b) << 21; - if b < 0x80 { - return Ok((u64::from(part0), 4)); - }; - part0 -= 0x80 << 21; - let value = u64::from(part0); - - b = unsafe { *bytes.get_unchecked(4) }; - let mut part1: u32 = u32::from(b); - if b < 0x80 { - return Ok((value + (u64::from(part1) << 28), 5)); - }; - part1 -= 0x80; - b = unsafe { *bytes.get_unchecked(5) }; - part1 += u32::from(b) << 7; - if b < 0x80 { - return Ok((value + (u64::from(part1) << 28), 6)); - }; - part1 -= 0x80 << 7; - b = unsafe { *bytes.get_unchecked(6) }; - part1 += u32::from(b) << 14; - if b < 0x80 { - return Ok((value + (u64::from(part1) << 28), 7)); - }; - part1 -= 0x80 << 14; - b = unsafe { *bytes.get_unchecked(7) }; - part1 += u32::from(b) << 21; - if b < 0x80 { - return Ok((value + (u64::from(part1) << 28), 8)); - }; - part1 -= 0x80 << 21; - let value = value + ((u64::from(part1)) << 28); - - b = unsafe { *bytes.get_unchecked(8) }; - let mut part2: u32 = u32::from(b); - if b < 0x80 { - return Ok((value + (u64::from(part2) << 56), 9)); - }; - part2 -= 0x80; - b = unsafe { *bytes.get_unchecked(9) }; - part2 += u32::from(b) << 7; - // Check for u64::MAX overflow. See [`ConsumeVarint`][1] for details. - // [1]: https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/encoding/protowire/wire.go#L358 - if b < 0x02 { - return Ok((value + (u64::from(part2) << 56), 10)); - }; +pub mod length_delimiter; +pub use length_delimiter::{ + decode_length_delimiter, encode_length_delimiter, length_delimiter_len, +}; - // We have overrun the maximum size of a varint (10 bytes) or the final byte caused an overflow. - // Assume the data is corrupt. - Err(DecodeError::new("invalid varint")) -} - -/// Decodes a LEB128-encoded variable length integer from the buffer, advancing the buffer as -/// necessary. -/// -/// Contains a varint overflow check from [`ConsumeVarint`][1]. -/// -/// [1]: https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/encoding/protowire/wire.go#L358 -#[inline(never)] -#[cold] -fn decode_varint_slow(buf: &mut B) -> Result -where - B: Buf, -{ - let mut value = 0; - for count in 0..min(10, buf.remaining()) { - let byte = buf.get_u8(); - value |= u64::from(byte & 0x7F) << (count * 7); - if byte <= 0x7F { - // Check for u64::MAX overflow. See [`ConsumeVarint`][1] for details. - // [1]: https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/encoding/protowire/wire.go#L358 - if count == 9 && byte >= 0x02 { - return Err(DecodeError::new("invalid varint")); - } else { - return Ok(value); - } - } - } - - Err(DecodeError::new("invalid varint")) -} +pub mod wire_type; +pub use wire_type::{check_wire_type, WireType}; /// Additional information passed to every decode/merge function. /// @@ -255,56 +97,13 @@ } } -/// Returns the encoded length of the value in LEB128 variable length format. -/// The returned value will be between 1 and 10, inclusive. -#[inline] -pub fn encoded_len_varint(value: u64) -> usize { - // Based on [VarintSize64][1]. - // [1]: https://github.com/google/protobuf/blob/3.3.x/src/google/protobuf/io/coded_stream.h#L1301-L1309 - ((((value | 1).leading_zeros() ^ 63) * 9 + 73) / 64) as usize -} - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[repr(u8)] -pub enum WireType { - Varint = 0, - SixtyFourBit = 1, - LengthDelimited = 2, - StartGroup = 3, - EndGroup = 4, - ThirtyTwoBit = 5, -} - pub const MIN_TAG: u32 = 1; pub const MAX_TAG: u32 = (1 << 29) - 1; -impl TryFrom for WireType { - type Error = DecodeError; - - #[inline] - fn try_from(value: u64) -> Result { - match value { - 0 => Ok(WireType::Varint), - 1 => Ok(WireType::SixtyFourBit), - 2 => Ok(WireType::LengthDelimited), - 3 => Ok(WireType::StartGroup), - 4 => Ok(WireType::EndGroup), - 5 => Ok(WireType::ThirtyTwoBit), - _ => Err(DecodeError::new(format!( - "invalid wire type value: {}", - value - ))), - } - } -} - /// Encodes a Protobuf field key, which consists of a wire type designator and /// the field tag. #[inline] -pub fn encode_key(tag: u32, wire_type: WireType, buf: &mut B) -where - B: BufMut, -{ +pub fn encode_key(tag: u32, wire_type: WireType, buf: &mut impl BufMut) { debug_assert!((MIN_TAG..=MAX_TAG).contains(&tag)); let key = (tag << 3) | wire_type as u32; encode_varint(u64::from(key), buf); @@ -313,10 +112,7 @@ /// Decodes a Protobuf field key, which consists of a wire type designator and /// the field tag. #[inline(always)] -pub fn decode_key(buf: &mut B) -> Result<(u32, WireType), DecodeError> -where - B: Buf, -{ +pub fn decode_key(buf: &mut impl Buf) -> Result<(u32, WireType), DecodeError> { let key = decode_varint(buf)?; if key > u64::from(u32::MAX) { return Err(DecodeError::new(format!("invalid key value: {}", key))); @@ -334,21 +130,8 @@ /// Returns the width of an encoded Protobuf field key with the given tag. /// The returned width will be between 1 and 5 bytes (inclusive). #[inline] -pub fn key_len(tag: u32) -> usize { - encoded_len_varint(u64::from(tag << 3)) -} - -/// Checks that the expected wire type matches the actual wire type, -/// or returns an error result. -#[inline] -pub fn check_wire_type(expected: WireType, actual: WireType) -> Result<(), DecodeError> { - if expected != actual { - return Err(DecodeError::new(format!( - "invalid wire type: {:?} (expected {:?})", - actual, expected - ))); - } - Ok(()) +pub const fn key_len(tag: u32) -> usize { + encoded_len_varint((tag << 3) as u64) } /// Helper function which abstracts reading a length delimiter prefix followed @@ -380,15 +163,12 @@ Ok(()) } -pub fn skip_field( +pub fn skip_field( wire_type: WireType, tag: u32, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, -) -> Result<(), DecodeError> -where - B: Buf, -{ +) -> Result<(), DecodeError> { ctx.limit_reached()?; let len = match wire_type { WireType::Varint => decode_varint(buf).map(|_| 0)?, @@ -421,10 +201,7 @@ /// Helper macro which emits an `encode_repeated` function for the type. macro_rules! encode_repeated { ($ty:ty) => { - pub fn encode_repeated(tag: u32, values: &[$ty], buf: &mut B) - where - B: BufMut, - { + pub fn encode_repeated(tag: u32, values: &[$ty], buf: &mut impl BufMut) { for value in values { encode(tag, value, buf); } @@ -438,15 +215,12 @@ $wire_type:expr, $merge:ident, $merge_repeated:ident) => { - pub fn $merge_repeated( + pub fn $merge_repeated( wire_type: WireType, values: &mut Vec<$ty>, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if wire_type == WireType::LengthDelimited { // Packed. merge_loop(values, buf, ctx, |values, buf, ctx| { @@ -486,12 +260,12 @@ pub mod $proto_ty { use crate::encoding::*; - pub fn encode(tag: u32, $to_uint64_value: &$ty, buf: &mut B) where B: BufMut { + pub fn encode(tag: u32, $to_uint64_value: &$ty, buf: &mut impl BufMut) { encode_key(tag, WireType::Varint, buf); encode_varint($to_uint64, buf); } - pub fn merge(wire_type: WireType, value: &mut $ty, buf: &mut B, _ctx: DecodeContext) -> Result<(), DecodeError> where B: Buf { + pub fn merge(wire_type: WireType, value: &mut $ty, buf: &mut impl Buf, _ctx: DecodeContext) -> Result<(), DecodeError> { check_wire_type(WireType::Varint, wire_type)?; let $from_uint64_value = decode_varint(buf)?; *value = $from_uint64; @@ -500,7 +274,7 @@ encode_repeated!($ty); - pub fn encode_packed(tag: u32, values: &[$ty], buf: &mut B) where B: BufMut { + pub fn encode_packed(tag: u32, values: &[$ty], buf: &mut impl BufMut) { if values.is_empty() { return; } encode_key(tag, WireType::LengthDelimited, buf); @@ -609,23 +383,17 @@ pub mod $proto_ty { use crate::encoding::*; - pub fn encode(tag: u32, value: &$ty, buf: &mut B) - where - B: BufMut, - { + pub fn encode(tag: u32, value: &$ty, buf: &mut impl BufMut) { encode_key(tag, $wire_type, buf); buf.$put(*value); } - pub fn merge( + pub fn merge( wire_type: WireType, value: &mut $ty, - buf: &mut B, + buf: &mut impl Buf, _ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { check_wire_type($wire_type, wire_type)?; if buf.remaining() < $width { return Err(DecodeError::new("buffer underflow")); @@ -636,10 +404,7 @@ encode_repeated!($ty); - pub fn encode_packed(tag: u32, values: &[$ty], buf: &mut B) - where - B: BufMut, - { + pub fn encode_packed(tag: u32, values: &[$ty], buf: &mut impl BufMut) { if values.is_empty() { return; } @@ -759,15 +524,12 @@ ($ty:ty) => { encode_repeated!($ty); - pub fn merge_repeated( + pub fn merge_repeated( wire_type: WireType, values: &mut Vec<$ty>, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { check_wire_type(WireType::LengthDelimited, wire_type)?; let mut value = Default::default(); merge(wire_type, &mut value, buf, ctx)?; @@ -794,23 +556,18 @@ pub mod string { use super::*; - pub fn encode(tag: u32, value: &String, buf: &mut B) - where - B: BufMut, - { + pub fn encode(tag: u32, value: &String, buf: &mut impl BufMut) { encode_key(tag, WireType::LengthDelimited, buf); encode_varint(value.len() as u64, buf); buf.put_slice(value.as_bytes()); } - pub fn merge( + + pub fn merge( wire_type: WireType, value: &mut String, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { // ## Unsafety // // `string::merge` reuses `bytes::merge`, with an additional check of utf-8 @@ -826,7 +583,7 @@ // in the buf implementation, a drop guard is used. unsafe { struct DropGuard<'a>(&'a mut Vec); - impl<'a> Drop for DropGuard<'a> { + impl Drop for DropGuard<'_> { #[inline] fn drop(&mut self) { self.0.clear(); @@ -882,14 +639,10 @@ fn len(&self) -> usize; /// Replace contents of this buffer with the contents of another buffer. - fn replace_with(&mut self, buf: B) - where - B: Buf; + fn replace_with(&mut self, buf: impl Buf); /// Appends this buffer to the (contents of) other buffer. - fn append_to(&self, buf: &mut B) - where - B: BufMut; + fn append_to(&self, buf: &mut impl BufMut); fn is_empty(&self) -> bool { self.len() == 0 @@ -904,17 +657,11 @@ Buf::remaining(self) } - fn replace_with(&mut self, mut buf: B) - where - B: Buf, - { + fn replace_with(&mut self, mut buf: impl Buf) { *self = buf.copy_to_bytes(buf.remaining()); } - fn append_to(&self, buf: &mut B) - where - B: BufMut, - { + fn append_to(&self, buf: &mut impl BufMut) { buf.put(self.clone()) } } @@ -926,19 +673,13 @@ Vec::len(self) } - fn replace_with(&mut self, buf: B) - where - B: Buf, - { + fn replace_with(&mut self, buf: impl Buf) { self.clear(); self.reserve(buf.remaining()); self.put(buf); } - fn append_to(&self, buf: &mut B) - where - B: BufMut, - { + fn append_to(&self, buf: &mut impl BufMut) { buf.put(self.as_slice()) } } @@ -946,26 +687,18 @@ pub mod bytes { use super::*; - pub fn encode(tag: u32, value: &A, buf: &mut B) - where - A: BytesAdapter, - B: BufMut, - { + pub fn encode(tag: u32, value: &impl BytesAdapter, buf: &mut impl BufMut) { encode_key(tag, WireType::LengthDelimited, buf); encode_varint(value.len() as u64, buf); value.append_to(buf); } - pub fn merge( + pub fn merge( wire_type: WireType, - value: &mut A, - buf: &mut B, + value: &mut impl BytesAdapter, + buf: &mut impl Buf, _ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - A: BytesAdapter, - B: Buf, - { + ) -> Result<(), DecodeError> { check_wire_type(WireType::LengthDelimited, wire_type)?; let len = decode_varint(buf)?; if len > buf.remaining() as u64 { @@ -989,16 +722,12 @@ Ok(()) } - pub(super) fn merge_one_copy( + pub(super) fn merge_one_copy( wire_type: WireType, - value: &mut A, - buf: &mut B, + value: &mut impl BytesAdapter, + buf: &mut impl Buf, _ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - A: BytesAdapter, - B: Buf, - { + ) -> Result<(), DecodeError> { check_wire_type(WireType::LengthDelimited, wire_type)?; let len = decode_varint(buf)?; if len > buf.remaining() as u64 { @@ -1055,10 +784,9 @@ pub mod message { use super::*; - pub fn encode(tag: u32, msg: &M, buf: &mut B) + pub fn encode(tag: u32, msg: &M, buf: &mut impl BufMut) where M: Message, - B: BufMut, { encode_key(tag, WireType::LengthDelimited, buf); encode_varint(msg.encoded_len() as u64, buf); @@ -1088,25 +816,23 @@ ) } - pub fn encode_repeated(tag: u32, messages: &[M], buf: &mut B) + pub fn encode_repeated(tag: u32, messages: &[M], buf: &mut impl BufMut) where M: Message, - B: BufMut, { for msg in messages { encode(tag, msg, buf); } } - pub fn merge_repeated( + pub fn merge_repeated( wire_type: WireType, messages: &mut Vec, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, ) -> Result<(), DecodeError> where M: Message + Default, - B: Buf, { check_wire_type(WireType::LengthDelimited, wire_type)?; let mut msg = M::default(); @@ -1141,26 +867,24 @@ pub mod group { use super::*; - pub fn encode(tag: u32, msg: &M, buf: &mut B) + pub fn encode(tag: u32, msg: &M, buf: &mut impl BufMut) where M: Message, - B: BufMut, { encode_key(tag, WireType::StartGroup, buf); msg.encode_raw(buf); encode_key(tag, WireType::EndGroup, buf); } - pub fn merge( + pub fn merge( tag: u32, wire_type: WireType, msg: &mut M, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, ) -> Result<(), DecodeError> where M: Message, - B: Buf, { check_wire_type(WireType::StartGroup, wire_type)?; @@ -1178,26 +902,24 @@ } } - pub fn encode_repeated(tag: u32, messages: &[M], buf: &mut B) + pub fn encode_repeated(tag: u32, messages: &[M], buf: &mut impl BufMut) where M: Message, - B: BufMut, { for msg in messages { encode(tag, msg, buf); } } - pub fn merge_repeated( + pub fn merge_repeated( tag: u32, wire_type: WireType, messages: &mut Vec, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, ) -> Result<(), DecodeError> where M: Message + Default, - B: Buf, { check_wire_type(WireType::StartGroup, wire_type)?; let mut msg = M::default(); @@ -1426,7 +1148,6 @@ use alloc::string::ToString; use core::borrow::Borrow; use core::fmt::Debug; - use core::u64; use ::bytes::BytesMut; use proptest::{prelude::*, test_runner::TestCaseResult}; @@ -1601,101 +1322,6 @@ assert!(s.is_empty()); } - #[test] - fn varint() { - fn check(value: u64, encoded: &[u8]) { - // Small buffer. - let mut buf = Vec::with_capacity(1); - encode_varint(value, &mut buf); - assert_eq!(buf, encoded); - - // Large buffer. - let mut buf = Vec::with_capacity(100); - encode_varint(value, &mut buf); - assert_eq!(buf, encoded); - - assert_eq!(encoded_len_varint(value), encoded.len()); - - // See: https://github.com/tokio-rs/prost/pull/1008 for copying reasoning. - let mut encoded_copy = encoded; - let roundtrip_value = decode_varint(&mut encoded_copy).expect("decoding failed"); - assert_eq!(value, roundtrip_value); - - let mut encoded_copy = encoded; - let roundtrip_value = - decode_varint_slow(&mut encoded_copy).expect("slow decoding failed"); - assert_eq!(value, roundtrip_value); - } - - check(2u64.pow(0) - 1, &[0x00]); - check(2u64.pow(0), &[0x01]); - - check(2u64.pow(7) - 1, &[0x7F]); - check(2u64.pow(7), &[0x80, 0x01]); - check(300, &[0xAC, 0x02]); - - check(2u64.pow(14) - 1, &[0xFF, 0x7F]); - check(2u64.pow(14), &[0x80, 0x80, 0x01]); - - check(2u64.pow(21) - 1, &[0xFF, 0xFF, 0x7F]); - check(2u64.pow(21), &[0x80, 0x80, 0x80, 0x01]); - - check(2u64.pow(28) - 1, &[0xFF, 0xFF, 0xFF, 0x7F]); - check(2u64.pow(28), &[0x80, 0x80, 0x80, 0x80, 0x01]); - - check(2u64.pow(35) - 1, &[0xFF, 0xFF, 0xFF, 0xFF, 0x7F]); - check(2u64.pow(35), &[0x80, 0x80, 0x80, 0x80, 0x80, 0x01]); - - check(2u64.pow(42) - 1, &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F]); - check(2u64.pow(42), &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01]); - - check( - 2u64.pow(49) - 1, - &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], - ); - check( - 2u64.pow(49), - &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01], - ); - - check( - 2u64.pow(56) - 1, - &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], - ); - check( - 2u64.pow(56), - &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01], - ); - - check( - 2u64.pow(63) - 1, - &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F], - ); - check( - 2u64.pow(63), - &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01], - ); - - check( - u64::MAX, - &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01], - ); - } - - const U64_MAX_PLUS_ONE: &[u8] = &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x02]; - - #[test] - fn varint_overflow() { - let mut copy = U64_MAX_PLUS_ONE; - decode_varint(&mut copy).expect_err("decoding u64::MAX + 1 succeeded"); - } - - #[test] - fn variant_slow_overflow() { - let mut copy = U64_MAX_PLUS_ONE; - decode_varint_slow(&mut copy).expect_err("slow decoding u64::MAX + 1 succeeded"); - } - /// This big bowl o' macro soup generates an encoding property test for each combination of map /// type, scalar map key, and value type. /// TODO: these tests take a long time to compile, can this be improved? diff -Nru rust-prost-0.12.6/src/error.rs rust-prost-0.13.5/src/error.rs --- rust-prost-0.12.6/src/error.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prost-0.13.5/src/error.rs 2006-07-24 01:21:28.000000000 +0000 @@ -131,3 +131,50 @@ std::io::Error::new(std::io::ErrorKind::InvalidInput, error) } } + +/// An error indicating that an unknown enumeration value was encountered. +/// +/// The Protobuf spec mandates that enumeration value sets are ‘open’, so this +/// error's value represents an integer value unrecognized by the +/// presently used enum definition. +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub struct UnknownEnumValue(pub i32); + +impl fmt::Display for UnknownEnumValue { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "unknown enumeration value {}", self.0) + } +} + +#[cfg(feature = "std")] +impl std::error::Error for UnknownEnumValue {} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_push() { + let mut decode_error = DecodeError::new("something failed"); + decode_error.push("Foo bad", "bar.foo"); + decode_error.push("Baz bad", "bar.baz"); + + assert_eq!( + decode_error.to_string(), + "failed to decode Protobuf message: Foo bad.bar.foo: Baz bad.bar.baz: something failed" + ); + } + + #[cfg(feature = "std")] + #[test] + fn test_into_std_io_error() { + let decode_error = DecodeError::new("something failed"); + let std_io_error = std::io::Error::from(decode_error); + + assert_eq!(std_io_error.kind(), std::io::ErrorKind::InvalidData); + assert_eq!( + std_io_error.to_string(), + "failed to decode Protobuf message: something failed" + ); + } +} diff -Nru rust-prost-0.12.6/src/lib.rs rust-prost-0.13.5/src/lib.rs --- rust-prost-0.12.6/src/lib.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prost-0.13.5/src/lib.rs 2006-07-24 01:21:28.000000000 +0000 @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/prost/0.12.6")] +#![doc(html_root_url = "https://docs.rs/prost/0.13.5")] #![cfg_attr(not(feature = "std"), no_std)] #![doc = include_str!("../README.md")] @@ -17,71 +17,18 @@ #[doc(hidden)] pub mod encoding; -pub use crate::error::{DecodeError, EncodeError}; +pub use crate::encoding::length_delimiter::{ + decode_length_delimiter, encode_length_delimiter, length_delimiter_len, +}; +pub use crate::error::{DecodeError, EncodeError, UnknownEnumValue}; pub use crate::message::Message; pub use crate::name::Name; -use bytes::{Buf, BufMut}; - -use crate::encoding::{decode_varint, encode_varint, encoded_len_varint}; - // See `encoding::DecodeContext` for more info. // 100 is the default recursion limit in the C++ implementation. #[cfg(not(feature = "no-recursion-limit"))] const RECURSION_LIMIT: u32 = 100; -/// Encodes a length delimiter to the buffer. -/// -/// See [Message.encode_length_delimited] for more info. -/// -/// An error will be returned if the buffer does not have sufficient capacity to encode the -/// delimiter. -pub fn encode_length_delimiter(length: usize, buf: &mut B) -> Result<(), EncodeError> -where - B: BufMut, -{ - let length = length as u64; - let required = encoded_len_varint(length); - let remaining = buf.remaining_mut(); - if required > remaining { - return Err(EncodeError::new(required, remaining)); - } - encode_varint(length, buf); - Ok(()) -} - -/// Returns the encoded length of a length delimiter. -/// -/// Applications may use this method to ensure sufficient buffer capacity before calling -/// `encode_length_delimiter`. The returned size will be between 1 and 10, inclusive. -pub fn length_delimiter_len(length: usize) -> usize { - encoded_len_varint(length as u64) -} - -/// Decodes a length delimiter from the buffer. -/// -/// This method allows the length delimiter to be decoded independently of the message, when the -/// message is encoded with [Message.encode_length_delimited]. -/// -/// An error may be returned in two cases: -/// -/// * If the supplied buffer contains fewer than 10 bytes, then an error indicates that more -/// input is required to decode the full delimiter. -/// * If the supplied buffer contains more than 10 bytes, then the buffer contains an invalid -/// delimiter, and typically the buffer should be considered corrupt. -pub fn decode_length_delimiter(mut buf: B) -> Result -where - B: Buf, -{ - let length = decode_varint(&mut buf)?; - if length > usize::max_value() as u64 { - return Err(DecodeError::new( - "length delimiter exceeds maximum usize value", - )); - } - Ok(length as usize) -} - // Re-export #[derive(Message, Enumeration, Oneof)]. // Based on serde's equivalent re-export [1], but enabled by default. // diff -Nru rust-prost-0.12.6/src/message.rs rust-prost-0.13.5/src/message.rs --- rust-prost-0.12.6/src/message.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prost-0.13.5/src/message.rs 2006-07-24 01:21:28.000000000 +0000 @@ -7,9 +7,9 @@ use bytes::{Buf, BufMut}; -use crate::encoding::{ - decode_key, encode_varint, encoded_len_varint, message, DecodeContext, WireType, -}; +use crate::encoding::varint::{encode_varint, encoded_len_varint}; +use crate::encoding::wire_type::WireType; +use crate::encoding::{decode_key, message, DecodeContext}; use crate::DecodeError; use crate::EncodeError; @@ -21,24 +21,22 @@ /// /// Meant to be used only by `Message` implementations. #[doc(hidden)] - fn encode_raw(&self, buf: &mut B) + fn encode_raw(&self, buf: &mut impl BufMut) where - B: BufMut, Self: Sized; /// Decodes a field from a buffer, and merges it into `self`. /// /// Meant to be used only by `Message` implementations. #[doc(hidden)] - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, ) -> Result<(), DecodeError> where - B: Buf, Self: Sized; /// Returns the encoded length of the message without a length delimiter. @@ -47,9 +45,8 @@ /// Encodes the message to a buffer. /// /// An error will be returned if the buffer does not have sufficient capacity. - fn encode(&self, buf: &mut B) -> Result<(), EncodeError> + fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> where - B: BufMut, Self: Sized, { let required = self.encoded_len(); @@ -76,9 +73,8 @@ /// Encodes the message with a length-delimiter to a buffer. /// /// An error will be returned if the buffer does not have sufficient capacity. - fn encode_length_delimited(&self, buf: &mut B) -> Result<(), EncodeError> + fn encode_length_delimited(&self, buf: &mut impl BufMut) -> Result<(), EncodeError> where - B: BufMut, Self: Sized, { let len = self.encoded_len(); @@ -108,9 +104,8 @@ /// Decodes an instance of the message from a buffer. /// /// The entire buffer will be consumed. - fn decode(mut buf: B) -> Result + fn decode(mut buf: impl Buf) -> Result where - B: Buf, Self: Default, { let mut message = Self::default(); @@ -118,9 +113,8 @@ } /// Decodes a length-delimited instance of the message from the buffer. - fn decode_length_delimited(buf: B) -> Result + fn decode_length_delimited(buf: impl Buf) -> Result where - B: Buf, Self: Default, { let mut message = Self::default(); @@ -131,9 +125,8 @@ /// Decodes an instance of the message from a buffer, and merges it into `self`. /// /// The entire buffer will be consumed. - fn merge(&mut self, mut buf: B) -> Result<(), DecodeError> + fn merge(&mut self, mut buf: impl Buf) -> Result<(), DecodeError> where - B: Buf, Self: Sized, { let ctx = DecodeContext::default(); @@ -146,9 +139,8 @@ /// Decodes a length-delimited instance of the message from buffer, and /// merges it into `self`. - fn merge_length_delimited(&mut self, mut buf: B) -> Result<(), DecodeError> + fn merge_length_delimited(&mut self, mut buf: impl Buf) -> Result<(), DecodeError> where - B: Buf, Self: Sized, { message::merge( @@ -167,22 +159,16 @@ where M: Message, { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { (**self).encode_raw(buf) } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { (**self).merge_field(tag, wire_type, buf, ctx) } fn encoded_len(&self) -> usize { diff -Nru rust-prost-0.12.6/src/name.rs rust-prost-0.13.5/src/name.rs --- rust-prost-0.12.6/src/name.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prost-0.13.5/src/name.rs 2006-07-24 01:21:28.000000000 +0000 @@ -27,7 +27,7 @@ /// Type URL for this [`Message`], which by default is the full name with a /// leading slash, but may also include a leading domain name, e.g. /// `type.googleapis.com/google.profile.Person`. - /// This can be used when serializing with the [`Any`] type. + /// This can be used when serializing into the `google.protobuf.Any` type. fn type_url() -> String { format!("/{}", Self::full_name()) } diff -Nru rust-prost-0.12.6/src/types.rs rust-prost-0.13.5/src/types.rs --- rust-prost-0.12.6/src/types.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prost-0.13.5/src/types.rs 2006-07-24 01:21:28.000000000 +0000 @@ -5,41 +5,34 @@ //! the `prost-types` crate in order to avoid a cyclic dependency between `prost` and //! `prost-build`. -#[cfg(not(feature = "std"))] +use alloc::format; use alloc::string::String; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; use ::bytes::{Buf, BufMut, Bytes}; +use crate::encoding::wire_type::WireType; use crate::{ encoding::{ - bool, bytes, double, float, int32, int64, skip_field, string, uint32, uint64, - DecodeContext, WireType, + bool, bytes, double, float, int32, int64, skip_field, string, uint32, uint64, DecodeContext, }, - DecodeError, Message, + DecodeError, Message, Name, }; /// `google.protobuf.BoolValue` impl Message for bool { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self { bool::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { bool::merge(wire_type, self, buf, ctx) } else { @@ -58,26 +51,30 @@ } } +/// `google.protobuf.BoolValue` +impl Name for bool { + const NAME: &'static str = "BoolValue"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + /// `google.protobuf.UInt32Value` impl Message for u32 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0 { uint32::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { uint32::merge(wire_type, self, buf, ctx) } else { @@ -96,26 +93,30 @@ } } +/// `google.protobuf.UInt32Value` +impl Name for u32 { + const NAME: &'static str = "UInt32Value"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + /// `google.protobuf.UInt64Value` impl Message for u64 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0 { uint64::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { uint64::merge(wire_type, self, buf, ctx) } else { @@ -134,26 +135,30 @@ } } +/// `google.protobuf.UInt64Value` +impl Name for u64 { + const NAME: &'static str = "UInt64Value"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + /// `google.protobuf.Int32Value` impl Message for i32 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0 { int32::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { int32::merge(wire_type, self, buf, ctx) } else { @@ -172,26 +177,30 @@ } } +/// `google.protobuf.Int32Value` +impl Name for i32 { + const NAME: &'static str = "Int32Value"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + /// `google.protobuf.Int64Value` impl Message for i64 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0 { int64::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { int64::merge(wire_type, self, buf, ctx) } else { @@ -210,26 +219,30 @@ } } +/// `google.protobuf.Int64Value` +impl Name for i64 { + const NAME: &'static str = "Int64Value"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + /// `google.protobuf.FloatValue` impl Message for f32 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0.0 { float::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { float::merge(wire_type, self, buf, ctx) } else { @@ -248,26 +261,30 @@ } } +/// `google.protobuf.FloatValue` +impl Name for f32 { + const NAME: &'static str = "FloatValue"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + /// `google.protobuf.DoubleValue` impl Message for f64 { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if *self != 0.0 { double::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { double::merge(wire_type, self, buf, ctx) } else { @@ -286,26 +303,30 @@ } } +/// `google.protobuf.DoubleValue` +impl Name for f64 { + const NAME: &'static str = "DoubleValue"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + /// `google.protobuf.StringValue` impl Message for String { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if !self.is_empty() { string::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { string::merge(wire_type, self, buf, ctx) } else { @@ -324,26 +345,30 @@ } } +/// `google.protobuf.StringValue` +impl Name for String { + const NAME: &'static str = "StringValue"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + /// `google.protobuf.BytesValue` impl Message for Vec { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if !self.is_empty() { bytes::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { bytes::merge(wire_type, self, buf, ctx) } else { @@ -363,25 +388,29 @@ } /// `google.protobuf.BytesValue` +impl Name for Vec { + const NAME: &'static str = "BytesValue"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + +/// `google.protobuf.BytesValue` impl Message for Bytes { - fn encode_raw(&self, buf: &mut B) - where - B: BufMut, - { + fn encode_raw(&self, buf: &mut impl BufMut) { if !self.is_empty() { bytes::encode(1, self, buf) } } - fn merge_field( + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { if tag == 1 { bytes::merge(wire_type, self, buf, ctx) } else { @@ -400,23 +429,26 @@ } } +/// `google.protobuf.BytesValue` +impl Name for Bytes { + const NAME: &'static str = "BytesValue"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + /// `google.protobuf.Empty` impl Message for () { - fn encode_raw(&self, _buf: &mut B) - where - B: BufMut, - { - } - fn merge_field( + fn encode_raw(&self, _buf: &mut impl BufMut) {} + fn merge_field( &mut self, tag: u32, wire_type: WireType, - buf: &mut B, + buf: &mut impl Buf, ctx: DecodeContext, - ) -> Result<(), DecodeError> - where - B: Buf, - { + ) -> Result<(), DecodeError> { skip_field(wire_type, tag, buf, ctx) } fn encoded_len(&self) -> usize { @@ -424,3 +456,115 @@ } fn clear(&mut self) {} } + +/// `google.protobuf.Empty` +impl Name for () { + const NAME: &'static str = "Empty"; + const PACKAGE: &'static str = "google.protobuf"; + + fn type_url() -> String { + googleapis_type_url_for::() + } +} + +/// Compute the type URL for the given `google.protobuf` type, using `type.googleapis.com` as the +/// authority for the URL. +fn googleapis_type_url_for() -> String { + format!("type.googleapis.com/{}.{}", T::PACKAGE, T::NAME) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_impl_name() { + assert_eq!("BoolValue", bool::NAME); + assert_eq!("google.protobuf", bool::PACKAGE); + assert_eq!("google.protobuf.BoolValue", bool::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.BoolValue", + bool::type_url() + ); + + assert_eq!("UInt32Value", u32::NAME); + assert_eq!("google.protobuf", u32::PACKAGE); + assert_eq!("google.protobuf.UInt32Value", u32::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.UInt32Value", + u32::type_url() + ); + + assert_eq!("UInt64Value", u64::NAME); + assert_eq!("google.protobuf", u64::PACKAGE); + assert_eq!("google.protobuf.UInt64Value", u64::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.UInt64Value", + u64::type_url() + ); + + assert_eq!("Int32Value", i32::NAME); + assert_eq!("google.protobuf", i32::PACKAGE); + assert_eq!("google.protobuf.Int32Value", i32::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.Int32Value", + i32::type_url() + ); + + assert_eq!("Int64Value", i64::NAME); + assert_eq!("google.protobuf", i64::PACKAGE); + assert_eq!("google.protobuf.Int64Value", i64::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.Int64Value", + i64::type_url() + ); + + assert_eq!("FloatValue", f32::NAME); + assert_eq!("google.protobuf", f32::PACKAGE); + assert_eq!("google.protobuf.FloatValue", f32::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.FloatValue", + f32::type_url() + ); + + assert_eq!("DoubleValue", f64::NAME); + assert_eq!("google.protobuf", f64::PACKAGE); + assert_eq!("google.protobuf.DoubleValue", f64::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.DoubleValue", + f64::type_url() + ); + + assert_eq!("StringValue", String::NAME); + assert_eq!("google.protobuf", String::PACKAGE); + assert_eq!("google.protobuf.StringValue", String::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.StringValue", + String::type_url() + ); + + assert_eq!("BytesValue", Vec::::NAME); + assert_eq!("google.protobuf", Vec::::PACKAGE); + assert_eq!("google.protobuf.BytesValue", Vec::::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.BytesValue", + Vec::::type_url() + ); + + assert_eq!("BytesValue", Bytes::NAME); + assert_eq!("google.protobuf", Bytes::PACKAGE); + assert_eq!("google.protobuf.BytesValue", Bytes::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.BytesValue", + Bytes::type_url() + ); + + assert_eq!("Empty", <()>::NAME); + assert_eq!("google.protobuf", <()>::PACKAGE); + assert_eq!("google.protobuf.Empty", <()>::full_name()); + assert_eq!( + "type.googleapis.com/google.protobuf.Empty", + <()>::type_url() + ); + } +}