Coverage Report

Created: 2025-02-25 06:39

/rust/registry/src/index.crates.io-6f17d22bba15001f/prost-0.13.4/src/encoding.rs
Line
Count
Source (jump to first uncovered line)
1
//! Utility functions and types for encoding and decoding Protobuf types.
2
//!
3
//! Meant to be used only from `Message` implementations.
4
5
#![allow(clippy::implicit_hasher, clippy::ptr_arg)]
6
7
use alloc::collections::BTreeMap;
8
use alloc::format;
9
use alloc::string::String;
10
use alloc::vec::Vec;
11
use core::mem;
12
use core::str;
13
14
use ::bytes::{Buf, BufMut, Bytes};
15
16
use crate::DecodeError;
17
use crate::Message;
18
19
pub mod varint;
20
pub use varint::{decode_varint, encode_varint, encoded_len_varint};
21
22
pub mod length_delimiter;
23
pub use length_delimiter::{
24
    decode_length_delimiter, encode_length_delimiter, length_delimiter_len,
25
};
26
27
pub mod wire_type;
28
pub use wire_type::{check_wire_type, WireType};
29
30
/// Additional information passed to every decode/merge function.
31
///
32
/// The context should be passed by value and can be freely cloned. When passing
33
/// to a function which is decoding a nested object, then use `enter_recursion`.
34
#[derive(Clone, Debug)]
35
#[cfg_attr(feature = "no-recursion-limit", derive(Default))]
36
pub struct DecodeContext {
37
    /// How many times we can recurse in the current decode stack before we hit
38
    /// the recursion limit.
39
    ///
40
    /// The recursion limit is defined by `RECURSION_LIMIT` and cannot be
41
    /// customized. The recursion limit can be ignored by building the Prost
42
    /// crate with the `no-recursion-limit` feature.
43
    #[cfg(not(feature = "no-recursion-limit"))]
44
    recurse_count: u32,
45
}
46
47
#[cfg(not(feature = "no-recursion-limit"))]
48
impl Default for DecodeContext {
49
    #[inline]
50
20.2k
    fn default() -> DecodeContext {
51
20.2k
        DecodeContext {
52
20.2k
            recurse_count: crate::RECURSION_LIMIT,
53
20.2k
        }
54
20.2k
    }
Unexecuted instantiation: <prost::encoding::DecodeContext as core::default::Default>::default
Unexecuted instantiation: <prost::encoding::DecodeContext as core::default::Default>::default
<prost::encoding::DecodeContext as core::default::Default>::default
Line
Count
Source
50
20.2k
    fn default() -> DecodeContext {
51
20.2k
        DecodeContext {
52
20.2k
            recurse_count: crate::RECURSION_LIMIT,
53
20.2k
        }
54
20.2k
    }
55
}
56
57
impl DecodeContext {
58
    /// Call this function before recursively decoding.
59
    ///
60
    /// There is no `exit` function since this function creates a new `DecodeContext`
61
    /// to be used at the next level of recursion. Continue to use the old context
62
    // at the previous level of recursion.
63
    #[cfg(not(feature = "no-recursion-limit"))]
64
    #[inline]
65
2.09M
    pub(crate) fn enter_recursion(&self) -> DecodeContext {
66
2.09M
        DecodeContext {
67
2.09M
            recurse_count: self.recurse_count - 1,
68
2.09M
        }
69
2.09M
    }
<prost::encoding::DecodeContext>::enter_recursion
Line
Count
Source
65
16.6k
    pub(crate) fn enter_recursion(&self) -> DecodeContext {
66
16.6k
        DecodeContext {
67
16.6k
            recurse_count: self.recurse_count - 1,
68
16.6k
        }
69
16.6k
    }
Unexecuted instantiation: <prost::encoding::DecodeContext>::enter_recursion
<prost::encoding::DecodeContext>::enter_recursion
Line
Count
Source
65
2.07M
    pub(crate) fn enter_recursion(&self) -> DecodeContext {
66
2.07M
        DecodeContext {
67
2.07M
            recurse_count: self.recurse_count - 1,
68
2.07M
        }
69
2.07M
    }
70
71
    #[cfg(feature = "no-recursion-limit")]
72
    #[inline]
73
    pub(crate) fn enter_recursion(&self) -> DecodeContext {
74
        DecodeContext {}
75
    }
76
77
    /// Checks whether the recursion limit has been reached in the stack of
78
    /// decodes described by the `DecodeContext` at `self.ctx`.
79
    ///
80
    /// Returns `Ok<()>` if it is ok to continue recursing.
81
    /// Returns `Err<DecodeError>` if the recursion limit has been reached.
82
    #[cfg(not(feature = "no-recursion-limit"))]
83
    #[inline]
84
3.61M
    pub(crate) fn limit_reached(&self) -> Result<(), DecodeError> {
85
3.61M
        if self.recurse_count == 0 {
86
6
            Err(DecodeError::new("recursion limit reached"))
87
        } else {
88
3.61M
            Ok(())
89
        }
90
3.61M
    }
<prost::encoding::DecodeContext>::limit_reached
Line
Count
Source
84
1.53M
    pub(crate) fn limit_reached(&self) -> Result<(), DecodeError> {
85
1.53M
        if self.recurse_count == 0 {
86
6
            Err(DecodeError::new("recursion limit reached"))
87
        } else {
88
1.53M
            Ok(())
89
        }
90
1.53M
    }
Unexecuted instantiation: <prost::encoding::DecodeContext>::limit_reached
<prost::encoding::DecodeContext>::limit_reached
Line
Count
Source
84
2.07M
    pub(crate) fn limit_reached(&self) -> Result<(), DecodeError> {
85
2.07M
        if self.recurse_count == 0 {
86
0
            Err(DecodeError::new("recursion limit reached"))
87
        } else {
88
2.07M
            Ok(())
89
        }
90
2.07M
    }
91
92
    #[cfg(feature = "no-recursion-limit")]
93
    #[inline]
94
    #[allow(clippy::unnecessary_wraps)] // needed in other features
95
    pub(crate) fn limit_reached(&self) -> Result<(), DecodeError> {
96
        Ok(())
97
    }
98
}
99
100
pub const MIN_TAG: u32 = 1;
101
pub const MAX_TAG: u32 = (1 << 29) - 1;
102
103
/// Encodes a Protobuf field key, which consists of a wire type designator and
104
/// the field tag.
105
#[inline]
106
0
pub fn encode_key(tag: u32, wire_type: WireType, buf: &mut impl BufMut) {
107
0
    debug_assert!((MIN_TAG..=MAX_TAG).contains(&tag));
108
0
    let key = (tag << 3) | wire_type as u32;
109
0
    encode_varint(u64::from(key), buf);
110
0
}
Unexecuted instantiation: prost::encoding::encode_key::<alloc::vec::Vec<u8>>
Unexecuted instantiation: prost::encoding::encode_key::<tonic::codec::buffer::EncodeBuf>
Unexecuted instantiation: prost::encoding::encode_key::<_>
111
112
/// Decodes a Protobuf field key, which consists of a wire type designator and
113
/// the field tag.
114
#[inline(always)]
115
7.54M
pub fn decode_key(buf: &mut impl Buf) -> Result<(u32, WireType), DecodeError> {
116
7.54M
    let key = decode_varint(buf)?;
117
7.53M
    if key > u64::from(u32::MAX) {
118
460
        return Err(DecodeError::new(format!("invalid key value: {}", key)));
119
7.53M
    }
120
7.53M
    let wire_type = WireType::try_from(key & 0x07)?;
121
7.53M
    let tag = key as u32 >> 3;
122
7.53M
123
7.53M
    if tag < MIN_TAG {
124
1.67k
        return Err(DecodeError::new("invalid tag value: 0"));
125
7.53M
    }
126
7.53M
127
7.53M
    Ok((tag, wire_type))
128
7.54M
}
prost::encoding::decode_key::<&mut &[u8]>
Line
Count
Source
115
17.6k
pub fn decode_key(buf: &mut impl Buf) -> Result<(u32, WireType), DecodeError> {
116
17.6k
    let key = decode_varint(buf)?;
117
17.3k
    if key > u64::from(u32::MAX) {
118
33
        return Err(DecodeError::new(format!("invalid key value: {}", key)));
119
17.2k
    }
120
17.2k
    let wire_type = WireType::try_from(key & 0x07)?;
121
17.1k
    let tag = key as u32 >> 3;
122
17.1k
123
17.1k
    if tag < MIN_TAG {
124
187
        return Err(DecodeError::new("invalid tag value: 0"));
125
16.9k
    }
126
16.9k
127
16.9k
    Ok((tag, wire_type))
128
17.6k
}
Unexecuted instantiation: prost::encoding::decode_key::<&mut &mut tonic::codec::buffer::DecodeBuf>
Unexecuted instantiation: prost::encoding::decode_key::<_>
prost::encoding::decode_key::<&mut &[u8]>
Line
Count
Source
115
7.52M
pub fn decode_key(buf: &mut impl Buf) -> Result<(u32, WireType), DecodeError> {
116
7.52M
    let key = decode_varint(buf)?;
117
7.52M
    if key > u64::from(u32::MAX) {
118
427
        return Err(DecodeError::new(format!("invalid key value: {}", key)));
119
7.52M
    }
120
7.52M
    let wire_type = WireType::try_from(key & 0x07)?;
121
7.52M
    let tag = key as u32 >> 3;
122
7.52M
123
7.52M
    if tag < MIN_TAG {
124
1.48k
        return Err(DecodeError::new("invalid tag value: 0"));
125
7.51M
    }
126
7.51M
127
7.51M
    Ok((tag, wire_type))
128
7.52M
}
129
130
/// Returns the width of an encoded Protobuf field key with the given tag.
131
/// The returned width will be between 1 and 5 bytes (inclusive).
132
#[inline]
133
0
pub fn key_len(tag: u32) -> usize {
134
0
    encoded_len_varint(u64::from(tag << 3))
135
0
}
Unexecuted instantiation: prost::encoding::key_len
Unexecuted instantiation: prost::encoding::key_len
136
137
/// Helper function which abstracts reading a length delimiter prefix followed
138
/// by decoding values until the length of bytes is exhausted.
139
2.08M
pub fn merge_loop<T, M, B>(
140
2.08M
    value: &mut T,
141
2.08M
    buf: &mut B,
142
2.08M
    ctx: DecodeContext,
143
2.08M
    mut merge: M,
144
2.08M
) -> Result<(), DecodeError>
145
2.08M
where
146
2.08M
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
2.08M
    B: Buf,
148
2.08M
{
149
2.08M
    let len = decode_varint(buf)?;
150
2.08M
    let remaining = buf.remaining();
151
2.08M
    if len > remaining as u64 {
152
1.19k
        return Err(DecodeError::new("buffer underflow"));
153
2.08M
    }
154
2.08M
155
2.08M
    let limit = remaining - len as usize;
156
4.30M
    while buf.remaining() > limit {
157
2.23M
        merge(value, buf, ctx.clone())?;
158
    }
159
160
2.07M
    if buf.remaining() != limit {
161
1.09k
        return Err(DecodeError::new("delimited length exceeded"));
162
2.07M
    }
163
2.07M
    Ok(())
164
2.08M
}
Unexecuted instantiation: prost::encoding::merge_loop::<ztunnel::inpod::istio::zds::AddWorkload, prost::encoding::message::merge<ztunnel::inpod::istio::zds::AddWorkload, &mut &[u8]>::{closure#0}, &mut &[u8]>
Unexecuted instantiation: prost::encoding::merge_loop::<ztunnel::inpod::istio::zds::DelWorkload, prost::encoding::message::merge<ztunnel::inpod::istio::zds::DelWorkload, &mut &[u8]>::{closure#0}, &mut &[u8]>
Unexecuted instantiation: prost::encoding::merge_loop::<ztunnel::inpod::istio::zds::KeepWorkload, prost::encoding::message::merge<ztunnel::inpod::istio::zds::KeepWorkload, &mut &[u8]>::{closure#0}, &mut &[u8]>
Unexecuted instantiation: prost::encoding::merge_loop::<ztunnel::inpod::istio::zds::SnapshotSent, prost::encoding::message::merge<ztunnel::inpod::istio::zds::SnapshotSent, &mut &[u8]>::{closure#0}, &mut &[u8]>
Unexecuted instantiation: prost::encoding::merge_loop::<ztunnel::inpod::istio::zds::WorkloadInfo, prost::encoding::message::merge<ztunnel::inpod::istio::zds::WorkloadInfo, &mut &[u8]>::{closure#0}, &mut &[u8]>
Unexecuted instantiation: prost::encoding::merge_loop::<_, _, _>
prost::encoding::merge_loop::<alloc::vec::Vec<u32>, prost::encoding::uint32::merge_repeated<&mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
10.2k
pub fn merge_loop<T, M, B>(
140
10.2k
    value: &mut T,
141
10.2k
    buf: &mut B,
142
10.2k
    ctx: DecodeContext,
143
10.2k
    mut merge: M,
144
10.2k
) -> Result<(), DecodeError>
145
10.2k
where
146
10.2k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
10.2k
    B: Buf,
148
10.2k
{
149
10.2k
    let len = decode_varint(buf)?;
150
10.2k
    let remaining = buf.remaining();
151
10.2k
    if len > remaining as u64 {
152
164
        return Err(DecodeError::new("buffer underflow"));
153
10.0k
    }
154
10.0k
155
10.0k
    let limit = remaining - len as usize;
156
1.22M
    while buf.remaining() > limit {
157
1.21M
        merge(value, buf, ctx.clone())?;
158
    }
159
160
10.0k
    if buf.remaining() != limit {
161
8
        return Err(DecodeError::new("delimited length exceeded"));
162
10.0k
    }
163
10.0k
    Ok(())
164
10.2k
}
prost::encoding::merge_loop::<prost_types::protobuf::Any, prost::encoding::message::merge<prost_types::protobuf::Any, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
2.38k
pub fn merge_loop<T, M, B>(
140
2.38k
    value: &mut T,
141
2.38k
    buf: &mut B,
142
2.38k
    ctx: DecodeContext,
143
2.38k
    mut merge: M,
144
2.38k
) -> Result<(), DecodeError>
145
2.38k
where
146
2.38k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
2.38k
    B: Buf,
148
2.38k
{
149
2.38k
    let len = decode_varint(buf)?;
150
2.36k
    let remaining = buf.remaining();
151
2.36k
    if len > remaining as u64 {
152
19
        return Err(DecodeError::new("buffer underflow"));
153
2.34k
    }
154
2.34k
155
2.34k
    let limit = remaining - len as usize;
156
39.0k
    while buf.remaining() > limit {
157
36.9k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
2.19k
    if buf.remaining() != limit {
161
25
        return Err(DecodeError::new("delimited length exceeded"));
162
2.17k
    }
163
2.17k
    Ok(())
164
2.38k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::security::StringMatch, prost::encoding::message::merge<ztunnel::xds::types::istio::security::StringMatch, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
278k
pub fn merge_loop<T, M, B>(
140
278k
    value: &mut T,
141
278k
    buf: &mut B,
142
278k
    ctx: DecodeContext,
143
278k
    mut merge: M,
144
278k
) -> Result<(), DecodeError>
145
278k
where
146
278k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
278k
    B: Buf,
148
278k
{
149
278k
    let len = decode_varint(buf)?;
150
278k
    let remaining = buf.remaining();
151
278k
    if len > remaining as u64 {
152
28
        return Err(DecodeError::new("buffer underflow"));
153
278k
    }
154
278k
155
278k
    let limit = remaining - len as usize;
156
386k
    while buf.remaining() > limit {
157
108k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
278k
    if buf.remaining() != limit {
161
69
        return Err(DecodeError::new("delimited length exceeded"));
162
278k
    }
163
278k
    Ok(())
164
278k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::security::ServiceAccountMatch, prost::encoding::message::merge<ztunnel::xds::types::istio::security::ServiceAccountMatch, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
10.8k
pub fn merge_loop<T, M, B>(
140
10.8k
    value: &mut T,
141
10.8k
    buf: &mut B,
142
10.8k
    ctx: DecodeContext,
143
10.8k
    mut merge: M,
144
10.8k
) -> Result<(), DecodeError>
145
10.8k
where
146
10.8k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
10.8k
    B: Buf,
148
10.8k
{
149
10.8k
    let len = decode_varint(buf)?;
150
10.8k
    let remaining = buf.remaining();
151
10.8k
    if len > remaining as u64 {
152
17
        return Err(DecodeError::new("buffer underflow"));
153
10.7k
    }
154
10.7k
155
10.7k
    let limit = remaining - len as usize;
156
37.2k
    while buf.remaining() > limit {
157
26.6k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
10.6k
    if buf.remaining() != limit {
161
18
        return Err(DecodeError::new("delimited length exceeded"));
162
10.6k
    }
163
10.6k
    Ok(())
164
10.8k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::security::Rule, prost::encoding::message::merge<ztunnel::xds::types::istio::security::Rule, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
1.37M
pub fn merge_loop<T, M, B>(
140
1.37M
    value: &mut T,
141
1.37M
    buf: &mut B,
142
1.37M
    ctx: DecodeContext,
143
1.37M
    mut merge: M,
144
1.37M
) -> Result<(), DecodeError>
145
1.37M
where
146
1.37M
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
1.37M
    B: Buf,
148
1.37M
{
149
1.37M
    let len = decode_varint(buf)?;
150
1.37M
    let remaining = buf.remaining();
151
1.37M
    if len > remaining as u64 {
152
149
        return Err(DecodeError::new("buffer underflow"));
153
1.37M
    }
154
1.37M
155
1.37M
    let limit = remaining - len as usize;
156
1.41M
    while buf.remaining() > limit {
157
47.9k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
1.36M
    if buf.remaining() != limit {
161
77
        return Err(DecodeError::new("delimited length exceeded"));
162
1.36M
    }
163
1.36M
    Ok(())
164
1.37M
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::security::Match, prost::encoding::message::merge<ztunnel::xds::types::istio::security::Match, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
28.6k
pub fn merge_loop<T, M, B>(
140
28.6k
    value: &mut T,
141
28.6k
    buf: &mut B,
142
28.6k
    ctx: DecodeContext,
143
28.6k
    mut merge: M,
144
28.6k
) -> Result<(), DecodeError>
145
28.6k
where
146
28.6k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
28.6k
    B: Buf,
148
28.6k
{
149
28.6k
    let len = decode_varint(buf)?;
150
28.6k
    let remaining = buf.remaining();
151
28.6k
    if len > remaining as u64 {
152
27
        return Err(DecodeError::new("buffer underflow"));
153
28.5k
    }
154
28.5k
155
28.5k
    let limit = remaining - len as usize;
156
525k
    while buf.remaining() > limit {
157
498k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
27.0k
    if buf.remaining() != limit {
161
209
        return Err(DecodeError::new("delimited length exceeded"));
162
26.8k
    }
163
26.8k
    Ok(())
164
28.6k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::security::Clause, prost::encoding::message::merge<ztunnel::xds::types::istio::security::Clause, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
26.8k
pub fn merge_loop<T, M, B>(
140
26.8k
    value: &mut T,
141
26.8k
    buf: &mut B,
142
26.8k
    ctx: DecodeContext,
143
26.8k
    mut merge: M,
144
26.8k
) -> Result<(), DecodeError>
145
26.8k
where
146
26.8k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
26.8k
    B: Buf,
148
26.8k
{
149
26.8k
    let len = decode_varint(buf)?;
150
26.8k
    let remaining = buf.remaining();
151
26.8k
    if len > remaining as u64 {
152
113
        return Err(DecodeError::new("buffer underflow"));
153
26.7k
    }
154
26.7k
155
26.7k
    let limit = remaining - len as usize;
156
59.7k
    while buf.remaining() > limit {
157
34.9k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
24.7k
    if buf.remaining() != limit {
161
116
        return Err(DecodeError::new("delimited length exceeded"));
162
24.6k
    }
163
24.6k
    Ok(())
164
26.8k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::security::Address, prost::encoding::message::merge<ztunnel::xds::types::istio::security::Address, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
191k
pub fn merge_loop<T, M, B>(
140
191k
    value: &mut T,
141
191k
    buf: &mut B,
142
191k
    ctx: DecodeContext,
143
191k
    mut merge: M,
144
191k
) -> Result<(), DecodeError>
145
191k
where
146
191k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
191k
    B: Buf,
148
191k
{
149
191k
    let len = decode_varint(buf)?;
150
191k
    let remaining = buf.remaining();
151
191k
    if len > remaining as u64 {
152
24
        return Err(DecodeError::new("buffer underflow"));
153
191k
    }
154
191k
155
191k
    let limit = remaining - len as usize;
156
204k
    while buf.remaining() > limit {
157
13.5k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
191k
    if buf.remaining() != limit {
161
27
        return Err(DecodeError::new("delimited length exceeded"));
162
190k
    }
163
190k
    Ok(())
164
191k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::workload::GatewayAddress, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::GatewayAddress, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
4.48k
pub fn merge_loop<T, M, B>(
140
4.48k
    value: &mut T,
141
4.48k
    buf: &mut B,
142
4.48k
    ctx: DecodeContext,
143
4.48k
    mut merge: M,
144
4.48k
) -> Result<(), DecodeError>
145
4.48k
where
146
4.48k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
4.48k
    B: Buf,
148
4.48k
{
149
4.48k
    let len = decode_varint(buf)?;
150
4.45k
    let remaining = buf.remaining();
151
4.45k
    if len > remaining as u64 {
152
159
        return Err(DecodeError::new("buffer underflow"));
153
4.29k
    }
154
4.29k
155
4.29k
    let limit = remaining - len as usize;
156
16.3k
    while buf.remaining() > limit {
157
13.0k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
3.24k
    if buf.remaining() != limit {
161
105
        return Err(DecodeError::new("delimited length exceeded"));
162
3.13k
    }
163
3.13k
    Ok(())
164
4.48k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::workload::NetworkAddress, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::NetworkAddress, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
4.21k
pub fn merge_loop<T, M, B>(
140
4.21k
    value: &mut T,
141
4.21k
    buf: &mut B,
142
4.21k
    ctx: DecodeContext,
143
4.21k
    mut merge: M,
144
4.21k
) -> Result<(), DecodeError>
145
4.21k
where
146
4.21k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
4.21k
    B: Buf,
148
4.21k
{
149
4.21k
    let len = decode_varint(buf)?;
150
4.19k
    let remaining = buf.remaining();
151
4.19k
    if len > remaining as u64 {
152
29
        return Err(DecodeError::new("buffer underflow"));
153
4.16k
    }
154
4.16k
155
4.16k
    let limit = remaining - len as usize;
156
69.8k
    while buf.remaining() > limit {
157
66.0k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
3.78k
    if buf.remaining() != limit {
161
137
        return Err(DecodeError::new("delimited length exceeded"));
162
3.64k
    }
163
3.64k
    Ok(())
164
4.21k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::workload::ApplicationTunnel, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::ApplicationTunnel, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
2.04k
pub fn merge_loop<T, M, B>(
140
2.04k
    value: &mut T,
141
2.04k
    buf: &mut B,
142
2.04k
    ctx: DecodeContext,
143
2.04k
    mut merge: M,
144
2.04k
) -> Result<(), DecodeError>
145
2.04k
where
146
2.04k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
2.04k
    B: Buf,
148
2.04k
{
149
2.04k
    let len = decode_varint(buf)?;
150
2.02k
    let remaining = buf.remaining();
151
2.02k
    if len > remaining as u64 {
152
117
        return Err(DecodeError::new("buffer underflow"));
153
1.90k
    }
154
1.90k
155
1.90k
    let limit = remaining - len as usize;
156
6.58k
    while buf.remaining() > limit {
157
4.86k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
1.72k
    if buf.remaining() != limit {
161
42
        return Err(DecodeError::new("delimited length exceeded"));
162
1.68k
    }
163
1.68k
    Ok(())
164
2.04k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::workload::NamespacedHostname, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::NamespacedHostname, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
3.56k
pub fn merge_loop<T, M, B>(
140
3.56k
    value: &mut T,
141
3.56k
    buf: &mut B,
142
3.56k
    ctx: DecodeContext,
143
3.56k
    mut merge: M,
144
3.56k
) -> Result<(), DecodeError>
145
3.56k
where
146
3.56k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
3.56k
    B: Buf,
148
3.56k
{
149
3.56k
    let len = decode_varint(buf)?;
150
3.54k
    let remaining = buf.remaining();
151
3.54k
    if len > remaining as u64 {
152
49
        return Err(DecodeError::new("buffer underflow"));
153
3.49k
    }
154
3.49k
155
3.49k
    let limit = remaining - len as usize;
156
10.2k
    while buf.remaining() > limit {
157
6.97k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
3.30k
    if buf.remaining() != limit {
161
35
        return Err(DecodeError::new("delimited length exceeded"));
162
3.26k
    }
163
3.26k
    Ok(())
164
3.56k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::workload::Port, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::Port, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
4.66k
pub fn merge_loop<T, M, B>(
140
4.66k
    value: &mut T,
141
4.66k
    buf: &mut B,
142
4.66k
    ctx: DecodeContext,
143
4.66k
    mut merge: M,
144
4.66k
) -> Result<(), DecodeError>
145
4.66k
where
146
4.66k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
4.66k
    B: Buf,
148
4.66k
{
149
4.66k
    let len = decode_varint(buf)?;
150
4.64k
    let remaining = buf.remaining();
151
4.64k
    if len > remaining as u64 {
152
16
        return Err(DecodeError::new("buffer underflow"));
153
4.62k
    }
154
4.62k
155
4.62k
    let limit = remaining - len as usize;
156
6.08k
    while buf.remaining() > limit {
157
1.53k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
4.54k
    if buf.remaining() != limit {
161
25
        return Err(DecodeError::new("delimited length exceeded"));
162
4.52k
    }
163
4.52k
    Ok(())
164
4.66k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::workload::Locality, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::Locality, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
1.74k
pub fn merge_loop<T, M, B>(
140
1.74k
    value: &mut T,
141
1.74k
    buf: &mut B,
142
1.74k
    ctx: DecodeContext,
143
1.74k
    mut merge: M,
144
1.74k
) -> Result<(), DecodeError>
145
1.74k
where
146
1.74k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
1.74k
    B: Buf,
148
1.74k
{
149
1.74k
    let len = decode_varint(buf)?;
150
1.72k
    let remaining = buf.remaining();
151
1.72k
    if len > remaining as u64 {
152
34
        return Err(DecodeError::new("buffer underflow"));
153
1.69k
    }
154
1.69k
155
1.69k
    let limit = remaining - len as usize;
156
8.52k
    while buf.remaining() > limit {
157
7.01k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
1.51k
    if buf.remaining() != limit {
161
30
        return Err(DecodeError::new("delimited length exceeded"));
162
1.48k
    }
163
1.48k
    Ok(())
164
1.74k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::workload::PortList, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::PortList, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
3.92k
pub fn merge_loop<T, M, B>(
140
3.92k
    value: &mut T,
141
3.92k
    buf: &mut B,
142
3.92k
    ctx: DecodeContext,
143
3.92k
    mut merge: M,
144
3.92k
) -> Result<(), DecodeError>
145
3.92k
where
146
3.92k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
3.92k
    B: Buf,
148
3.92k
{
149
3.92k
    let len = decode_varint(buf)?;
150
3.91k
    let remaining = buf.remaining();
151
3.91k
    if len > remaining as u64 {
152
24
        return Err(DecodeError::new("buffer underflow"));
153
3.89k
    }
154
3.89k
155
3.89k
    let limit = remaining - len as usize;
156
10.9k
    while buf.remaining() > limit {
157
7.29k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
3.63k
    if buf.remaining() != limit {
161
42
        return Err(DecodeError::new("delimited length exceeded"));
162
3.58k
    }
163
3.58k
    Ok(())
164
3.92k
}
prost::encoding::merge_loop::<ztunnel::xds::types::istio::workload::Extension, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::Extension, &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
7.62k
pub fn merge_loop<T, M, B>(
140
7.62k
    value: &mut T,
141
7.62k
    buf: &mut B,
142
7.62k
    ctx: DecodeContext,
143
7.62k
    mut merge: M,
144
7.62k
) -> Result<(), DecodeError>
145
7.62k
where
146
7.62k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
7.62k
    B: Buf,
148
7.62k
{
149
7.62k
    let len = decode_varint(buf)?;
150
7.60k
    let remaining = buf.remaining();
151
7.60k
    if len > remaining as u64 {
152
24
        return Err(DecodeError::new("buffer underflow"));
153
7.58k
    }
154
7.58k
155
7.58k
    let limit = remaining - len as usize;
156
17.3k
    while buf.remaining() > limit {
157
10.1k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
7.21k
    if buf.remaining() != limit {
161
39
        return Err(DecodeError::new("delimited length exceeded"));
162
7.17k
    }
163
7.17k
    Ok(())
164
7.62k
}
prost::encoding::merge_loop::<(&mut alloc::string::String, &mut ztunnel::xds::types::istio::workload::PortList), prost::encoding::hash_map::merge_with_default<alloc::string::String, ztunnel::xds::types::istio::workload::PortList, &mut &[u8], prost::encoding::string::merge<&mut &[u8]>, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::PortList, &mut &[u8]>>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
128k
pub fn merge_loop<T, M, B>(
140
128k
    value: &mut T,
141
128k
    buf: &mut B,
142
128k
    ctx: DecodeContext,
143
128k
    mut merge: M,
144
128k
) -> Result<(), DecodeError>
145
128k
where
146
128k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
128k
    B: Buf,
148
128k
{
149
128k
    let len = decode_varint(buf)?;
150
128k
    let remaining = buf.remaining();
151
128k
    if len > remaining as u64 {
152
56
        return Err(DecodeError::new("buffer underflow"));
153
128k
    }
154
128k
155
128k
    let limit = remaining - len as usize;
156
260k
    while buf.remaining() > limit {
157
132k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
128k
    if buf.remaining() != limit {
161
39
        return Err(DecodeError::new("delimited length exceeded"));
162
128k
    }
163
128k
    Ok(())
164
128k
}
prost::encoding::merge_loop::<(), prost::encoding::message::merge<(), &mut &[u8]>::{closure#0}, &mut &[u8]>
Line
Count
Source
139
8.37k
pub fn merge_loop<T, M, B>(
140
8.37k
    value: &mut T,
141
8.37k
    buf: &mut B,
142
8.37k
    ctx: DecodeContext,
143
8.37k
    mut merge: M,
144
8.37k
) -> Result<(), DecodeError>
145
8.37k
where
146
8.37k
    M: FnMut(&mut T, &mut B, DecodeContext) -> Result<(), DecodeError>,
147
8.37k
    B: Buf,
148
8.37k
{
149
8.37k
    let len = decode_varint(buf)?;
150
8.35k
    let remaining = buf.remaining();
151
8.35k
    if len > remaining as u64 {
152
142
        return Err(DecodeError::new("buffer underflow"));
153
8.20k
    }
154
8.20k
155
8.20k
    let limit = remaining - len as usize;
156
12.8k
    while buf.remaining() > limit {
157
4.82k
        merge(value, buf, ctx.clone())?;
158
    }
159
160
8.05k
    if buf.remaining() != limit {
161
51
        return Err(DecodeError::new("delimited length exceeded"));
162
7.99k
    }
163
7.99k
    Ok(())
164
8.37k
}
165
166
1.53M
pub fn skip_field(
167
1.53M
    wire_type: WireType,
168
1.53M
    tag: u32,
169
1.53M
    buf: &mut impl Buf,
170
1.53M
    ctx: DecodeContext,
171
1.53M
) -> Result<(), DecodeError> {
172
1.53M
    ctx.limit_reached()?;
173
1.53M
    let len = match wire_type {
174
42.4k
        WireType::Varint => decode_varint(buf).map(|_| 0)?,
Unexecuted instantiation: prost::encoding::skip_field::<&mut &mut tonic::codec::buffer::DecodeBuf>::{closure#0}
prost::encoding::skip_field::<&mut &[u8]>::{closure#0}
Line
Count
Source
174
42.1k
        WireType::Varint => decode_varint(buf).map(|_| 0)?,
Unexecuted instantiation: prost::encoding::skip_field::<_>::{closure#0}
175
6.29k
        WireType::ThirtyTwoBit => 4,
176
9.16k
        WireType::SixtyFourBit => 8,
177
1.47M
        WireType::LengthDelimited => decode_varint(buf)?,
178
        WireType::StartGroup => loop {
179
17.6k
            let (inner_tag, inner_wire_type) = decode_key(buf)?;
180
16.9k
            match inner_wire_type {
181
                WireType::EndGroup => {
182
345
                    if inner_tag != tag {
183
95
                        return Err(DecodeError::new("unexpected end group tag"));
184
250
                    }
185
250
                    break 0;
186
                }
187
16.6k
                _ => skip_field(inner_wire_type, inner_tag, buf, ctx.enter_recursion())?,
188
            }
189
        },
190
215
        WireType::EndGroup => return Err(DecodeError::new("unexpected end group tag")),
191
    };
192
193
1.53M
    if len > buf.remaining() as u64 {
194
1.17k
        return Err(DecodeError::new("buffer underflow"));
195
1.53M
    }
196
1.53M
197
1.53M
    buf.advance(len as usize);
198
1.53M
    Ok(())
199
1.53M
}
Unexecuted instantiation: prost::encoding::skip_field::<&mut &mut tonic::codec::buffer::DecodeBuf>
prost::encoding::skip_field::<&mut &[u8]>
Line
Count
Source
166
1.53M
pub fn skip_field(
167
1.53M
    wire_type: WireType,
168
1.53M
    tag: u32,
169
1.53M
    buf: &mut impl Buf,
170
1.53M
    ctx: DecodeContext,
171
1.53M
) -> Result<(), DecodeError> {
172
1.53M
    ctx.limit_reached()?;
173
1.53M
    let len = match wire_type {
174
42.4k
        WireType::Varint => decode_varint(buf).map(|_| 0)?,
175
6.29k
        WireType::ThirtyTwoBit => 4,
176
9.16k
        WireType::SixtyFourBit => 8,
177
1.47M
        WireType::LengthDelimited => decode_varint(buf)?,
178
        WireType::StartGroup => loop {
179
17.6k
            let (inner_tag, inner_wire_type) = decode_key(buf)?;
180
16.9k
            match inner_wire_type {
181
                WireType::EndGroup => {
182
345
                    if inner_tag != tag {
183
95
                        return Err(DecodeError::new("unexpected end group tag"));
184
250
                    }
185
250
                    break 0;
186
                }
187
16.6k
                _ => skip_field(inner_wire_type, inner_tag, buf, ctx.enter_recursion())?,
188
            }
189
        },
190
215
        WireType::EndGroup => return Err(DecodeError::new("unexpected end group tag")),
191
    };
192
193
1.53M
    if len > buf.remaining() as u64 {
194
1.17k
        return Err(DecodeError::new("buffer underflow"));
195
1.53M
    }
196
1.53M
197
1.53M
    buf.advance(len as usize);
198
1.53M
    Ok(())
199
1.53M
}
Unexecuted instantiation: prost::encoding::skip_field::<_>
200
201
/// Helper macro which emits an `encode_repeated` function for the type.
202
macro_rules! encode_repeated {
203
    ($ty:ty) => {
204
0
        pub fn encode_repeated(tag: u32, values: &[$ty], buf: &mut impl BufMut) {
205
0
            for value in values {
206
0
                encode(tag, value, buf);
207
0
            }
208
0
        }
Unexecuted instantiation: prost::encoding::bool::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::int32::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::int64::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::uint32::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::uint64::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::sint32::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::sint64::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::float::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::double::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::fixed32::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::fixed64::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::sfixed32::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::sfixed64::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::string::encode_repeated::<_>
Unexecuted instantiation: prost::encoding::bytes::encode_repeated::<_, _>
209
    };
210
}
211
212
/// Helper macro which emits a `merge_repeated` function for the numeric type.
213
macro_rules! merge_repeated_numeric {
214
    ($ty:ty,
215
     $wire_type:expr,
216
     $merge:ident,
217
     $merge_repeated:ident) => {
218
12.8k
        pub fn $merge_repeated(
219
12.8k
            wire_type: WireType,
220
12.8k
            values: &mut Vec<$ty>,
221
12.8k
            buf: &mut impl Buf,
222
12.8k
            ctx: DecodeContext,
223
12.8k
        ) -> Result<(), DecodeError> {
224
12.8k
            if wire_type == WireType::LengthDelimited {
225
                // Packed.
226
1.21M
                merge_loop(values, buf, ctx, |values, buf, ctx| {
227
1.21M
                    let mut value = Default::default();
228
1.21M
                    $merge($wire_type, &mut value, buf, ctx)?;
229
1.21M
                    values.push(value);
230
1.21M
                    Ok(())
231
1.21M
                })
Unexecuted instantiation: prost::encoding::bool::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::int32::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::int64::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::uint32::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::uint64::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::sint32::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::sint64::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::float::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::double::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::fixed32::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::fixed64::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::sfixed32::merge_repeated::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::sfixed64::merge_repeated::<_>::{closure#0}
prost::encoding::uint32::merge_repeated::<&mut &[u8]>::{closure#0}
Line
Count
Source
226
1.21M
                merge_loop(values, buf, ctx, |values, buf, ctx| {
227
1.21M
                    let mut value = Default::default();
228
1.21M
                    $merge($wire_type, &mut value, buf, ctx)?;
229
1.21M
                    values.push(value);
230
1.21M
                    Ok(())
231
1.21M
                })
232
            } else {
233
                // Unpacked.
234
2.62k
                check_wire_type($wire_type, wire_type)?;
235
2.62k
                let mut value = Default::default();
236
2.62k
                $merge(wire_type, &mut value, buf, ctx)?;
237
2.62k
                values.push(value);
238
2.62k
                Ok(())
239
            }
240
12.8k
        }
Unexecuted instantiation: prost::encoding::bool::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::int32::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::int64::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::uint32::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::uint64::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::sint32::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::sint64::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::float::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::double::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::fixed32::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::fixed64::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::sfixed32::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::sfixed64::merge_repeated::<_>
prost::encoding::uint32::merge_repeated::<&mut &[u8]>
Line
Count
Source
218
12.8k
        pub fn $merge_repeated(
219
12.8k
            wire_type: WireType,
220
12.8k
            values: &mut Vec<$ty>,
221
12.8k
            buf: &mut impl Buf,
222
12.8k
            ctx: DecodeContext,
223
12.8k
        ) -> Result<(), DecodeError> {
224
12.8k
            if wire_type == WireType::LengthDelimited {
225
                // Packed.
226
10.2k
                merge_loop(values, buf, ctx, |values, buf, ctx| {
227
                    let mut value = Default::default();
228
                    $merge($wire_type, &mut value, buf, ctx)?;
229
                    values.push(value);
230
                    Ok(())
231
10.2k
                })
232
            } else {
233
                // Unpacked.
234
2.62k
                check_wire_type($wire_type, wire_type)?;
235
2.62k
                let mut value = Default::default();
236
2.62k
                $merge(wire_type, &mut value, buf, ctx)?;
237
2.62k
                values.push(value);
238
2.62k
                Ok(())
239
            }
240
12.8k
        }
241
    };
242
}
243
244
/// Macro which emits a module containing a set of encoding functions for a
245
/// variable width numeric type.
246
macro_rules! varint {
247
    ($ty:ty,
248
     $proto_ty:ident) => (
249
        varint!($ty,
250
                $proto_ty,
251
                to_uint64(value) { *value as u64 },
252
                from_uint64(value) { value as $ty });
253
    );
254
255
    ($ty:ty,
256
     $proto_ty:ident,
257
     to_uint64($to_uint64_value:ident) $to_uint64:expr,
258
     from_uint64($from_uint64_value:ident) $from_uint64:expr) => (
259
260
         pub mod $proto_ty {
261
            use crate::encoding::*;
262
263
0
            pub fn encode(tag: u32, $to_uint64_value: &$ty, buf: &mut impl BufMut) {
264
0
                encode_key(tag, WireType::Varint, buf);
265
0
                encode_varint($to_uint64, buf);
266
0
            }
Unexecuted instantiation: prost::encoding::int64::encode::<tonic::codec::buffer::EncodeBuf>
Unexecuted instantiation: prost::encoding::bool::encode::<tonic::codec::buffer::EncodeBuf>
Unexecuted instantiation: prost::encoding::int32::encode::<alloc::vec::Vec<u8>>
Unexecuted instantiation: prost::encoding::int32::encode::<tonic::codec::buffer::EncodeBuf>
Unexecuted instantiation: prost::encoding::bool::encode::<_>
Unexecuted instantiation: prost::encoding::int32::encode::<_>
Unexecuted instantiation: prost::encoding::int64::encode::<_>
Unexecuted instantiation: prost::encoding::uint32::encode::<_>
Unexecuted instantiation: prost::encoding::uint64::encode::<_>
Unexecuted instantiation: prost::encoding::sint32::encode::<_>
Unexecuted instantiation: prost::encoding::sint64::encode::<_>
267
268
1.23M
            pub fn merge(wire_type: WireType, value: &mut $ty, buf: &mut impl Buf, _ctx: DecodeContext) -> Result<(), DecodeError> {
269
1.23M
                check_wire_type(WireType::Varint, wire_type)?;
270
1.23M
                let $from_uint64_value = decode_varint(buf)?;
271
1.23M
                *value = $from_uint64;
272
1.23M
                Ok(())
273
1.23M
            }
Unexecuted instantiation: prost::encoding::bool::merge::<_>
Unexecuted instantiation: prost::encoding::int32::merge::<_>
Unexecuted instantiation: prost::encoding::int64::merge::<_>
Unexecuted instantiation: prost::encoding::uint32::merge::<_>
Unexecuted instantiation: prost::encoding::uint64::merge::<_>
Unexecuted instantiation: prost::encoding::sint32::merge::<_>
Unexecuted instantiation: prost::encoding::sint64::merge::<_>
prost::encoding::uint32::merge::<&mut &[u8]>
Line
Count
Source
268
1.21M
            pub fn merge(wire_type: WireType, value: &mut $ty, buf: &mut impl Buf, _ctx: DecodeContext) -> Result<(), DecodeError> {
269
1.21M
                check_wire_type(WireType::Varint, wire_type)?;
270
1.21M
                let $from_uint64_value = decode_varint(buf)?;
271
1.21M
                *value = $from_uint64;
272
1.21M
                Ok(())
273
1.21M
            }
prost::encoding::int32::merge::<&mut &[u8]>
Line
Count
Source
268
21.1k
            pub fn merge(wire_type: WireType, value: &mut $ty, buf: &mut impl Buf, _ctx: DecodeContext) -> Result<(), DecodeError> {
269
21.1k
                check_wire_type(WireType::Varint, wire_type)?;
270
17.0k
                let $from_uint64_value = decode_varint(buf)?;
271
16.9k
                *value = $from_uint64;
272
16.9k
                Ok(())
273
21.1k
            }
prost::encoding::bool::merge::<&mut &[u8]>
Line
Count
Source
268
1.38k
            pub fn merge(wire_type: WireType, value: &mut $ty, buf: &mut impl Buf, _ctx: DecodeContext) -> Result<(), DecodeError> {
269
1.38k
                check_wire_type(WireType::Varint, wire_type)?;
270
1.35k
                let $from_uint64_value = decode_varint(buf)?;
271
1.33k
                *value = $from_uint64;
272
1.33k
                Ok(())
273
1.38k
            }
274
275
            encode_repeated!($ty);
276
277
0
            pub fn encode_packed(tag: u32, values: &[$ty], buf: &mut impl BufMut) {
278
0
                if values.is_empty() { return; }
279
0
280
0
                encode_key(tag, WireType::LengthDelimited, buf);
281
0
                let len: usize = values.iter().map(|$to_uint64_value| {
282
0
                    encoded_len_varint($to_uint64)
283
0
                }).sum();
Unexecuted instantiation: prost::encoding::bool::encode_packed::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::int32::encode_packed::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::int64::encode_packed::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::uint32::encode_packed::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::uint64::encode_packed::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::sint32::encode_packed::<_>::{closure#0}
Unexecuted instantiation: prost::encoding::sint64::encode_packed::<_>::{closure#0}
284
0
                encode_varint(len as u64, buf);
285
286
0
                for $to_uint64_value in values {
287
0
                    encode_varint($to_uint64, buf);
288
0
                }
289
0
            }
Unexecuted instantiation: prost::encoding::bool::encode_packed::<_>
Unexecuted instantiation: prost::encoding::int32::encode_packed::<_>
Unexecuted instantiation: prost::encoding::int64::encode_packed::<_>
Unexecuted instantiation: prost::encoding::uint32::encode_packed::<_>
Unexecuted instantiation: prost::encoding::uint64::encode_packed::<_>
Unexecuted instantiation: prost::encoding::sint32::encode_packed::<_>
Unexecuted instantiation: prost::encoding::sint64::encode_packed::<_>
290
291
            merge_repeated_numeric!($ty, WireType::Varint, merge, merge_repeated);
292
293
            #[inline]
294
0
            pub fn encoded_len(tag: u32, $to_uint64_value: &$ty) -> usize {
295
0
                key_len(tag) + encoded_len_varint($to_uint64)
296
0
            }
Unexecuted instantiation: prost::encoding::int64::encoded_len
Unexecuted instantiation: prost::encoding::bool::encoded_len
Unexecuted instantiation: prost::encoding::int32::encoded_len
Unexecuted instantiation: prost::encoding::int32::encoded_len
Unexecuted instantiation: prost::encoding::int64::encoded_len
Unexecuted instantiation: prost::encoding::uint32::encoded_len
Unexecuted instantiation: prost::encoding::uint64::encoded_len
Unexecuted instantiation: prost::encoding::bool::encoded_len
Unexecuted instantiation: prost::encoding::sint32::encoded_len
Unexecuted instantiation: prost::encoding::sint64::encoded_len
297
298
            #[inline]
299
0
            pub fn encoded_len_repeated(tag: u32, values: &[$ty]) -> usize {
300
0
                key_len(tag) * values.len() + values.iter().map(|$to_uint64_value| {
301
0
                    encoded_len_varint($to_uint64)
302
0
                }).sum::<usize>()
Unexecuted instantiation: prost::encoding::bool::encoded_len_repeated::{closure#0}
Unexecuted instantiation: prost::encoding::int32::encoded_len_repeated::{closure#0}
Unexecuted instantiation: prost::encoding::int64::encoded_len_repeated::{closure#0}
Unexecuted instantiation: prost::encoding::uint32::encoded_len_repeated::{closure#0}
Unexecuted instantiation: prost::encoding::uint64::encoded_len_repeated::{closure#0}
Unexecuted instantiation: prost::encoding::sint32::encoded_len_repeated::{closure#0}
Unexecuted instantiation: prost::encoding::sint64::encoded_len_repeated::{closure#0}
303
0
            }
Unexecuted instantiation: prost::encoding::bool::encoded_len_repeated
Unexecuted instantiation: prost::encoding::int32::encoded_len_repeated
Unexecuted instantiation: prost::encoding::int64::encoded_len_repeated
Unexecuted instantiation: prost::encoding::uint32::encoded_len_repeated
Unexecuted instantiation: prost::encoding::uint64::encoded_len_repeated
Unexecuted instantiation: prost::encoding::sint32::encoded_len_repeated
Unexecuted instantiation: prost::encoding::sint64::encoded_len_repeated
304
305
            #[inline]
306
0
            pub fn encoded_len_packed(tag: u32, values: &[$ty]) -> usize {
307
0
                if values.is_empty() {
308
0
                    0
309
                } else {
310
0
                    let len = values.iter()
311
0
                                    .map(|$to_uint64_value| encoded_len_varint($to_uint64))
Unexecuted instantiation: prost::encoding::bool::encoded_len_packed::{closure#0}
Unexecuted instantiation: prost::encoding::int32::encoded_len_packed::{closure#0}
Unexecuted instantiation: prost::encoding::int64::encoded_len_packed::{closure#0}
Unexecuted instantiation: prost::encoding::uint32::encoded_len_packed::{closure#0}
Unexecuted instantiation: prost::encoding::uint64::encoded_len_packed::{closure#0}
Unexecuted instantiation: prost::encoding::sint32::encoded_len_packed::{closure#0}
Unexecuted instantiation: prost::encoding::sint64::encoded_len_packed::{closure#0}
312
0
                                    .sum::<usize>();
313
0
                    key_len(tag) + encoded_len_varint(len as u64) + len
314
                }
315
0
            }
Unexecuted instantiation: prost::encoding::bool::encoded_len_packed
Unexecuted instantiation: prost::encoding::int32::encoded_len_packed
Unexecuted instantiation: prost::encoding::int64::encoded_len_packed
Unexecuted instantiation: prost::encoding::uint32::encoded_len_packed
Unexecuted instantiation: prost::encoding::uint64::encoded_len_packed
Unexecuted instantiation: prost::encoding::sint32::encoded_len_packed
Unexecuted instantiation: prost::encoding::sint64::encoded_len_packed
316
317
            #[cfg(test)]
318
            mod test {
319
                use proptest::prelude::*;
320
321
                use crate::encoding::$proto_ty::*;
322
                use crate::encoding::test::{
323
                    check_collection_type,
324
                    check_type,
325
                };
326
327
                proptest! {
328
                    #[test]
329
                    fn check(value: $ty, tag in MIN_TAG..=MAX_TAG) {
330
                        check_type(value, tag, WireType::Varint,
331
                                   encode, merge, encoded_len)?;
332
                    }
333
                    #[test]
334
                    fn check_repeated(value: Vec<$ty>, tag in MIN_TAG..=MAX_TAG) {
335
                        check_collection_type(value, tag, WireType::Varint,
336
                                              encode_repeated, merge_repeated,
337
                                              encoded_len_repeated)?;
338
                    }
339
                    #[test]
340
                    fn check_packed(value: Vec<$ty>, tag in MIN_TAG..=MAX_TAG) {
341
                        check_type(value, tag, WireType::LengthDelimited,
342
                                   encode_packed, merge_repeated,
343
                                   encoded_len_packed)?;
344
                    }
345
                }
346
            }
347
         }
348
349
    );
350
}
351
varint!(bool, bool,
352
        to_uint64(value) u64::from(*value),
353
        from_uint64(value) value != 0);
354
varint!(i32, int32);
355
varint!(i64, int64);
356
varint!(u32, uint32);
357
varint!(u64, uint64);
358
varint!(i32, sint32,
359
to_uint64(value) {
360
    ((value << 1) ^ (value >> 31)) as u32 as u64
361
},
362
from_uint64(value) {
363
    let value = value as u32;
364
    ((value >> 1) as i32) ^ (-((value & 1) as i32))
365
});
366
varint!(i64, sint64,
367
to_uint64(value) {
368
    ((value << 1) ^ (value >> 63)) as u64
369
},
370
from_uint64(value) {
371
    ((value >> 1) as i64) ^ (-((value & 1) as i64))
372
});
373
374
/// Macro which emits a module containing a set of encoding functions for a
375
/// fixed width numeric type.
376
macro_rules! fixed_width {
377
    ($ty:ty,
378
     $width:expr,
379
     $wire_type:expr,
380
     $proto_ty:ident,
381
     $put:ident,
382
     $get:ident) => {
383
        pub mod $proto_ty {
384
            use crate::encoding::*;
385
386
0
            pub fn encode(tag: u32, value: &$ty, buf: &mut impl BufMut) {
387
0
                encode_key(tag, $wire_type, buf);
388
0
                buf.$put(*value);
389
0
            }
Unexecuted instantiation: prost::encoding::double::encode::<tonic::codec::buffer::EncodeBuf>
Unexecuted instantiation: prost::encoding::float::encode::<_>
Unexecuted instantiation: prost::encoding::double::encode::<_>
Unexecuted instantiation: prost::encoding::fixed32::encode::<_>
Unexecuted instantiation: prost::encoding::fixed64::encode::<_>
Unexecuted instantiation: prost::encoding::sfixed32::encode::<_>
Unexecuted instantiation: prost::encoding::sfixed64::encode::<_>
390
391
0
            pub fn merge(
392
0
                wire_type: WireType,
393
0
                value: &mut $ty,
394
0
                buf: &mut impl Buf,
395
0
                _ctx: DecodeContext,
396
0
            ) -> Result<(), DecodeError> {
397
0
                check_wire_type($wire_type, wire_type)?;
398
0
                if buf.remaining() < $width {
399
0
                    return Err(DecodeError::new("buffer underflow"));
400
0
                }
401
0
                *value = buf.$get();
402
0
                Ok(())
403
0
            }
Unexecuted instantiation: prost::encoding::float::merge::<_>
Unexecuted instantiation: prost::encoding::double::merge::<_>
Unexecuted instantiation: prost::encoding::fixed32::merge::<_>
Unexecuted instantiation: prost::encoding::fixed64::merge::<_>
Unexecuted instantiation: prost::encoding::sfixed32::merge::<_>
Unexecuted instantiation: prost::encoding::sfixed64::merge::<_>
404
405
            encode_repeated!($ty);
406
407
0
            pub fn encode_packed(tag: u32, values: &[$ty], buf: &mut impl BufMut) {
408
0
                if values.is_empty() {
409
0
                    return;
410
0
                }
411
0
412
0
                encode_key(tag, WireType::LengthDelimited, buf);
413
0
                let len = values.len() as u64 * $width;
414
0
                encode_varint(len as u64, buf);
415
416
0
                for value in values {
417
0
                    buf.$put(*value);
418
0
                }
419
0
            }
Unexecuted instantiation: prost::encoding::float::encode_packed::<_>
Unexecuted instantiation: prost::encoding::double::encode_packed::<_>
Unexecuted instantiation: prost::encoding::fixed32::encode_packed::<_>
Unexecuted instantiation: prost::encoding::fixed64::encode_packed::<_>
Unexecuted instantiation: prost::encoding::sfixed32::encode_packed::<_>
Unexecuted instantiation: prost::encoding::sfixed64::encode_packed::<_>
420
421
            merge_repeated_numeric!($ty, $wire_type, merge, merge_repeated);
422
423
            #[inline]
424
0
            pub fn encoded_len(tag: u32, _: &$ty) -> usize {
425
0
                key_len(tag) + $width
426
0
            }
Unexecuted instantiation: prost::encoding::double::encoded_len
Unexecuted instantiation: prost::encoding::float::encoded_len
Unexecuted instantiation: prost::encoding::double::encoded_len
Unexecuted instantiation: prost::encoding::fixed32::encoded_len
Unexecuted instantiation: prost::encoding::fixed64::encoded_len
Unexecuted instantiation: prost::encoding::sfixed32::encoded_len
Unexecuted instantiation: prost::encoding::sfixed64::encoded_len
427
428
            #[inline]
429
0
            pub fn encoded_len_repeated(tag: u32, values: &[$ty]) -> usize {
430
0
                (key_len(tag) + $width) * values.len()
431
0
            }
Unexecuted instantiation: prost::encoding::float::encoded_len_repeated
Unexecuted instantiation: prost::encoding::double::encoded_len_repeated
Unexecuted instantiation: prost::encoding::fixed32::encoded_len_repeated
Unexecuted instantiation: prost::encoding::fixed64::encoded_len_repeated
Unexecuted instantiation: prost::encoding::sfixed32::encoded_len_repeated
Unexecuted instantiation: prost::encoding::sfixed64::encoded_len_repeated
432
433
            #[inline]
434
0
            pub fn encoded_len_packed(tag: u32, values: &[$ty]) -> usize {
435
0
                if values.is_empty() {
436
0
                    0
437
                } else {
438
0
                    let len = $width * values.len();
439
0
                    key_len(tag) + encoded_len_varint(len as u64) + len
440
                }
441
0
            }
Unexecuted instantiation: prost::encoding::float::encoded_len_packed
Unexecuted instantiation: prost::encoding::double::encoded_len_packed
Unexecuted instantiation: prost::encoding::fixed32::encoded_len_packed
Unexecuted instantiation: prost::encoding::fixed64::encoded_len_packed
Unexecuted instantiation: prost::encoding::sfixed32::encoded_len_packed
Unexecuted instantiation: prost::encoding::sfixed64::encoded_len_packed
442
443
            #[cfg(test)]
444
            mod test {
445
                use proptest::prelude::*;
446
447
                use super::super::test::{check_collection_type, check_type};
448
                use super::*;
449
450
                proptest! {
451
                    #[test]
452
                    fn check(value: $ty, tag in MIN_TAG..=MAX_TAG) {
453
                        check_type(value, tag, $wire_type,
454
                                   encode, merge, encoded_len)?;
455
                    }
456
                    #[test]
457
                    fn check_repeated(value: Vec<$ty>, tag in MIN_TAG..=MAX_TAG) {
458
                        check_collection_type(value, tag, $wire_type,
459
                                              encode_repeated, merge_repeated,
460
                                              encoded_len_repeated)?;
461
                    }
462
                    #[test]
463
                    fn check_packed(value: Vec<$ty>, tag in MIN_TAG..=MAX_TAG) {
464
                        check_type(value, tag, WireType::LengthDelimited,
465
                                   encode_packed, merge_repeated,
466
                                   encoded_len_packed)?;
467
                    }
468
                }
469
            }
470
        }
471
    };
472
}
473
fixed_width!(
474
    f32,
475
    4,
476
    WireType::ThirtyTwoBit,
477
    float,
478
    put_f32_le,
479
    get_f32_le
480
);
481
fixed_width!(
482
    f64,
483
    8,
484
    WireType::SixtyFourBit,
485
    double,
486
    put_f64_le,
487
    get_f64_le
488
);
489
fixed_width!(
490
    u32,
491
    4,
492
    WireType::ThirtyTwoBit,
493
    fixed32,
494
    put_u32_le,
495
    get_u32_le
496
);
497
fixed_width!(
498
    u64,
499
    8,
500
    WireType::SixtyFourBit,
501
    fixed64,
502
    put_u64_le,
503
    get_u64_le
504
);
505
fixed_width!(
506
    i32,
507
    4,
508
    WireType::ThirtyTwoBit,
509
    sfixed32,
510
    put_i32_le,
511
    get_i32_le
512
);
513
fixed_width!(
514
    i64,
515
    8,
516
    WireType::SixtyFourBit,
517
    sfixed64,
518
    put_i64_le,
519
    get_i64_le
520
);
521
522
/// Macro which emits encoding functions for a length-delimited type.
523
macro_rules! length_delimited {
524
    ($ty:ty) => {
525
        encode_repeated!($ty);
526
527
3.55M
        pub fn merge_repeated(
528
3.55M
            wire_type: WireType,
529
3.55M
            values: &mut Vec<$ty>,
530
3.55M
            buf: &mut impl Buf,
531
3.55M
            ctx: DecodeContext,
532
3.55M
        ) -> Result<(), DecodeError> {
533
3.55M
            check_wire_type(WireType::LengthDelimited, wire_type)?;
534
3.55M
            let mut value = Default::default();
535
3.55M
            merge(wire_type, &mut value, buf, ctx)?;
536
3.55M
            values.push(value);
537
3.55M
            Ok(())
538
3.55M
        }
Unexecuted instantiation: prost::encoding::string::merge_repeated::<&mut &mut tonic::codec::buffer::DecodeBuf>
Unexecuted instantiation: prost::encoding::string::merge_repeated::<_>
Unexecuted instantiation: prost::encoding::bytes::merge_repeated::<_, _>
prost::encoding::bytes::merge_repeated::<bytes::bytes::Bytes, &mut &[u8]>
Line
Count
Source
527
1.94M
        pub fn merge_repeated(
528
1.94M
            wire_type: WireType,
529
1.94M
            values: &mut Vec<$ty>,
530
1.94M
            buf: &mut impl Buf,
531
1.94M
            ctx: DecodeContext,
532
1.94M
        ) -> Result<(), DecodeError> {
533
1.94M
            check_wire_type(WireType::LengthDelimited, wire_type)?;
534
1.94M
            let mut value = Default::default();
535
1.94M
            merge(wire_type, &mut value, buf, ctx)?;
536
1.94M
            values.push(value);
537
1.94M
            Ok(())
538
1.94M
        }
prost::encoding::string::merge_repeated::<&mut &[u8]>
Line
Count
Source
527
1.61M
        pub fn merge_repeated(
528
1.61M
            wire_type: WireType,
529
1.61M
            values: &mut Vec<$ty>,
530
1.61M
            buf: &mut impl Buf,
531
1.61M
            ctx: DecodeContext,
532
1.61M
        ) -> Result<(), DecodeError> {
533
1.61M
            check_wire_type(WireType::LengthDelimited, wire_type)?;
534
1.61M
            let mut value = Default::default();
535
1.61M
            merge(wire_type, &mut value, buf, ctx)?;
536
1.61M
            values.push(value);
537
1.61M
            Ok(())
538
1.61M
        }
539
540
        #[inline]
541
0
        pub fn encoded_len(tag: u32, value: &$ty) -> usize {
542
0
            key_len(tag) + encoded_len_varint(value.len() as u64) + value.len()
543
0
        }
Unexecuted instantiation: prost::encoding::string::encoded_len
Unexecuted instantiation: prost::encoding::string::encoded_len
Unexecuted instantiation: prost::encoding::bytes::encoded_len::<alloc::vec::Vec<u8>>
Unexecuted instantiation: prost::encoding::bytes::encoded_len::<bytes::bytes::Bytes>
544
545
        #[inline]
546
0
        pub fn encoded_len_repeated(tag: u32, values: &[$ty]) -> usize {
547
0
            key_len(tag) * values.len()
548
0
                + values
549
0
                    .iter()
550
0
                    .map(|value| encoded_len_varint(value.len() as u64) + value.len())
Unexecuted instantiation: prost::encoding::string::encoded_len_repeated::{closure#0}
Unexecuted instantiation: prost::encoding::bytes::encoded_len_repeated::<_>::{closure#0}
551
0
                    .sum::<usize>()
552
0
        }
Unexecuted instantiation: prost::encoding::string::encoded_len_repeated
Unexecuted instantiation: prost::encoding::bytes::encoded_len_repeated::<_>
553
    };
554
}
555
556
pub mod string {
557
    use super::*;
558
559
0
    pub fn encode(tag: u32, value: &String, buf: &mut impl BufMut) {
560
0
        encode_key(tag, WireType::LengthDelimited, buf);
561
0
        encode_varint(value.len() as u64, buf);
562
0
        buf.put_slice(value.as_bytes());
563
0
    }
Unexecuted instantiation: prost::encoding::string::encode::<alloc::vec::Vec<u8>>
Unexecuted instantiation: prost::encoding::string::encode::<tonic::codec::buffer::EncodeBuf>
Unexecuted instantiation: prost::encoding::string::encode::<_>
564
565
1.92M
    pub fn merge(
566
1.92M
        wire_type: WireType,
567
1.92M
        value: &mut String,
568
1.92M
        buf: &mut impl Buf,
569
1.92M
        ctx: DecodeContext,
570
1.92M
    ) -> Result<(), DecodeError> {
571
        // ## Unsafety
572
        //
573
        // `string::merge` reuses `bytes::merge`, with an additional check of utf-8
574
        // well-formedness. If the utf-8 is not well-formed, or if any other error occurs, then the
575
        // string is cleared, so as to avoid leaking a string field with invalid data.
576
        //
577
        // This implementation uses the unsafe `String::as_mut_vec` method instead of the safe
578
        // alternative of temporarily swapping an empty `String` into the field, because it results
579
        // in up to 10% better performance on the protobuf message decoding benchmarks.
580
        //
581
        // It's required when using `String::as_mut_vec` that invalid utf-8 data not be leaked into
582
        // the backing `String`. To enforce this, even in the event of a panic in `bytes::merge` or
583
        // in the buf implementation, a drop guard is used.
584
        unsafe {
585
            struct DropGuard<'a>(&'a mut Vec<u8>);
586
            impl Drop for DropGuard<'_> {
587
                #[inline]
588
1.46k
                fn drop(&mut self) {
589
1.46k
                    self.0.clear();
590
1.46k
                }
<prost::encoding::string::merge::DropGuard as core::ops::drop::Drop>::drop
Line
Count
Source
588
1.46k
                fn drop(&mut self) {
589
1.46k
                    self.0.clear();
590
1.46k
                }
Unexecuted instantiation: <prost::encoding::string::merge::DropGuard as core::ops::drop::Drop>::drop
591
            }
592
593
1.92M
            let drop_guard = DropGuard(value.as_mut_vec());
594
1.92M
            bytes::merge_one_copy(wire_type, drop_guard.0, buf, ctx)?;
595
1.92M
            match str::from_utf8(drop_guard.0) {
596
                Ok(_) => {
597
                    // Success; do not clear the bytes.
598
1.92M
                    mem::forget(drop_guard);
599
1.92M
                    Ok(())
600
                }
601
539
                Err(_) => Err(DecodeError::new(
602
539
                    "invalid string value: data is not UTF-8 encoded",
603
539
                )),
604
            }
605
        }
606
1.92M
    }
Unexecuted instantiation: prost::encoding::string::merge::<&mut &mut tonic::codec::buffer::DecodeBuf>
prost::encoding::string::merge::<&mut &[u8]>
Line
Count
Source
565
1.92M
    pub fn merge(
566
1.92M
        wire_type: WireType,
567
1.92M
        value: &mut String,
568
1.92M
        buf: &mut impl Buf,
569
1.92M
        ctx: DecodeContext,
570
1.92M
    ) -> Result<(), DecodeError> {
571
        // ## Unsafety
572
        //
573
        // `string::merge` reuses `bytes::merge`, with an additional check of utf-8
574
        // well-formedness. If the utf-8 is not well-formed, or if any other error occurs, then the
575
        // string is cleared, so as to avoid leaking a string field with invalid data.
576
        //
577
        // This implementation uses the unsafe `String::as_mut_vec` method instead of the safe
578
        // alternative of temporarily swapping an empty `String` into the field, because it results
579
        // in up to 10% better performance on the protobuf message decoding benchmarks.
580
        //
581
        // It's required when using `String::as_mut_vec` that invalid utf-8 data not be leaked into
582
        // the backing `String`. To enforce this, even in the event of a panic in `bytes::merge` or
583
        // in the buf implementation, a drop guard is used.
584
        unsafe {
585
            struct DropGuard<'a>(&'a mut Vec<u8>);
586
            impl Drop for DropGuard<'_> {
587
                #[inline]
588
                fn drop(&mut self) {
589
                    self.0.clear();
590
                }
591
            }
592
593
1.92M
            let drop_guard = DropGuard(value.as_mut_vec());
594
1.92M
            bytes::merge_one_copy(wire_type, drop_guard.0, buf, ctx)?;
595
1.92M
            match str::from_utf8(drop_guard.0) {
596
                Ok(_) => {
597
                    // Success; do not clear the bytes.
598
1.92M
                    mem::forget(drop_guard);
599
1.92M
                    Ok(())
600
                }
601
539
                Err(_) => Err(DecodeError::new(
602
539
                    "invalid string value: data is not UTF-8 encoded",
603
539
                )),
604
            }
605
        }
606
1.92M
    }
Unexecuted instantiation: prost::encoding::string::merge::<_>
607
608
    length_delimited!(String);
609
610
    #[cfg(test)]
611
    mod test {
612
        use proptest::prelude::*;
613
614
        use super::super::test::{check_collection_type, check_type};
615
        use super::*;
616
617
        proptest! {
618
            #[test]
619
            fn check(value: String, tag in MIN_TAG..=MAX_TAG) {
620
                super::test::check_type(value, tag, WireType::LengthDelimited,
621
                                        encode, merge, encoded_len)?;
622
            }
623
            #[test]
624
            fn check_repeated(value: Vec<String>, tag in MIN_TAG..=MAX_TAG) {
625
                super::test::check_collection_type(value, tag, WireType::LengthDelimited,
626
                                                   encode_repeated, merge_repeated,
627
                                                   encoded_len_repeated)?;
628
            }
629
        }
630
    }
631
}
632
633
pub trait BytesAdapter: sealed::BytesAdapter {}
634
635
mod sealed {
636
    use super::{Buf, BufMut};
637
638
    pub trait BytesAdapter: Default + Sized + 'static {
639
        fn len(&self) -> usize;
640
641
        /// Replace contents of this buffer with the contents of another buffer.
642
        fn replace_with(&mut self, buf: impl Buf);
643
644
        /// Appends this buffer to the (contents of) other buffer.
645
        fn append_to(&self, buf: &mut impl BufMut);
646
647
0
        fn is_empty(&self) -> bool {
648
0
            self.len() == 0
649
0
        }
650
    }
651
}
652
653
impl BytesAdapter for Bytes {}
654
655
impl sealed::BytesAdapter for Bytes {
656
0
    fn len(&self) -> usize {
657
0
        Buf::remaining(self)
658
0
    }
659
660
1.94M
    fn replace_with(&mut self, mut buf: impl Buf) {
661
1.94M
        *self = buf.copy_to_bytes(buf.remaining());
662
1.94M
    }
Unexecuted instantiation: <bytes::bytes::Bytes as prost::encoding::sealed::BytesAdapter>::replace_with::<_>
<bytes::bytes::Bytes as prost::encoding::sealed::BytesAdapter>::replace_with::<bytes::bytes::Bytes>
Line
Count
Source
660
1.94M
    fn replace_with(&mut self, mut buf: impl Buf) {
661
1.94M
        *self = buf.copy_to_bytes(buf.remaining());
662
1.94M
    }
663
664
0
    fn append_to(&self, buf: &mut impl BufMut) {
665
0
        buf.put(self.clone())
666
0
    }
667
}
668
669
impl BytesAdapter for Vec<u8> {}
670
671
impl sealed::BytesAdapter for Vec<u8> {
672
0
    fn len(&self) -> usize {
673
0
        Vec::len(self)
674
0
    }
675
676
1.93M
    fn replace_with(&mut self, buf: impl Buf) {
677
1.93M
        self.clear();
678
1.93M
        self.reserve(buf.remaining());
679
1.93M
        self.put(buf);
680
1.93M
    }
Unexecuted instantiation: <alloc::vec::Vec<u8> as prost::encoding::sealed::BytesAdapter>::replace_with::<bytes::buf::take::Take<&mut &mut &mut tonic::codec::buffer::DecodeBuf>>
<alloc::vec::Vec<u8> as prost::encoding::sealed::BytesAdapter>::replace_with::<bytes::buf::take::Take<&mut &mut &[u8]>>
Line
Count
Source
676
1.92M
    fn replace_with(&mut self, buf: impl Buf) {
677
1.92M
        self.clear();
678
1.92M
        self.reserve(buf.remaining());
679
1.92M
        self.put(buf);
680
1.92M
    }
Unexecuted instantiation: <alloc::vec::Vec<u8> as prost::encoding::sealed::BytesAdapter>::replace_with::<_>
<alloc::vec::Vec<u8> as prost::encoding::sealed::BytesAdapter>::replace_with::<bytes::bytes::Bytes>
Line
Count
Source
676
10.1k
    fn replace_with(&mut self, buf: impl Buf) {
677
10.1k
        self.clear();
678
10.1k
        self.reserve(buf.remaining());
679
10.1k
        self.put(buf);
680
10.1k
    }
681
682
0
    fn append_to(&self, buf: &mut impl BufMut) {
683
0
        buf.put(self.as_slice())
684
0
    }
685
}
686
687
pub mod bytes {
688
    use super::*;
689
690
0
    pub fn encode(tag: u32, value: &impl BytesAdapter, buf: &mut impl BufMut) {
691
0
        encode_key(tag, WireType::LengthDelimited, buf);
692
0
        encode_varint(value.len() as u64, buf);
693
0
        value.append_to(buf);
694
0
    }
695
696
1.95M
    pub fn merge(
697
1.95M
        wire_type: WireType,
698
1.95M
        value: &mut impl BytesAdapter,
699
1.95M
        buf: &mut impl Buf,
700
1.95M
        _ctx: DecodeContext,
701
1.95M
    ) -> Result<(), DecodeError> {
702
1.95M
        check_wire_type(WireType::LengthDelimited, wire_type)?;
703
1.95M
        let len = decode_varint(buf)?;
704
1.95M
        if len > buf.remaining() as u64 {
705
343
            return Err(DecodeError::new("buffer underflow"));
706
1.95M
        }
707
1.95M
        let len = len as usize;
708
1.95M
709
1.95M
        // Clear the existing value. This follows from the following rule in the encoding guide[1]:
710
1.95M
        //
711
1.95M
        // > Normally, an encoded message would never have more than one instance of a non-repeated
712
1.95M
        // > field. However, parsers are expected to handle the case in which they do. For numeric
713
1.95M
        // > types and strings, if the same field appears multiple times, the parser accepts the
714
1.95M
        // > last value it sees.
715
1.95M
        //
716
1.95M
        // [1]: https://developers.google.com/protocol-buffers/docs/encoding#optional
717
1.95M
        //
718
1.95M
        // This is intended for A and B both being Bytes so it is zero-copy.
719
1.95M
        // Some combinations of A and B types may cause a double-copy,
720
1.95M
        // in which case merge_one_copy() should be used instead.
721
1.95M
        value.replace_with(buf.copy_to_bytes(len));
722
1.95M
        Ok(())
723
1.95M
    }
Unexecuted instantiation: prost::encoding::bytes::merge::<_, _>
prost::encoding::bytes::merge::<alloc::vec::Vec<u8>, &mut &[u8]>
Line
Count
Source
696
10.3k
    pub fn merge(
697
10.3k
        wire_type: WireType,
698
10.3k
        value: &mut impl BytesAdapter,
699
10.3k
        buf: &mut impl Buf,
700
10.3k
        _ctx: DecodeContext,
701
10.3k
    ) -> Result<(), DecodeError> {
702
10.3k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
703
10.3k
        let len = decode_varint(buf)?;
704
10.2k
        if len > buf.remaining() as u64 {
705
169
            return Err(DecodeError::new("buffer underflow"));
706
10.1k
        }
707
10.1k
        let len = len as usize;
708
10.1k
709
10.1k
        // Clear the existing value. This follows from the following rule in the encoding guide[1]:
710
10.1k
        //
711
10.1k
        // > Normally, an encoded message would never have more than one instance of a non-repeated
712
10.1k
        // > field. However, parsers are expected to handle the case in which they do. For numeric
713
10.1k
        // > types and strings, if the same field appears multiple times, the parser accepts the
714
10.1k
        // > last value it sees.
715
10.1k
        //
716
10.1k
        // [1]: https://developers.google.com/protocol-buffers/docs/encoding#optional
717
10.1k
        //
718
10.1k
        // This is intended for A and B both being Bytes so it is zero-copy.
719
10.1k
        // Some combinations of A and B types may cause a double-copy,
720
10.1k
        // in which case merge_one_copy() should be used instead.
721
10.1k
        value.replace_with(buf.copy_to_bytes(len));
722
10.1k
        Ok(())
723
10.3k
    }
prost::encoding::bytes::merge::<bytes::bytes::Bytes, &mut &[u8]>
Line
Count
Source
696
1.94M
    pub fn merge(
697
1.94M
        wire_type: WireType,
698
1.94M
        value: &mut impl BytesAdapter,
699
1.94M
        buf: &mut impl Buf,
700
1.94M
        _ctx: DecodeContext,
701
1.94M
    ) -> Result<(), DecodeError> {
702
1.94M
        check_wire_type(WireType::LengthDelimited, wire_type)?;
703
1.94M
        let len = decode_varint(buf)?;
704
1.94M
        if len > buf.remaining() as u64 {
705
174
            return Err(DecodeError::new("buffer underflow"));
706
1.94M
        }
707
1.94M
        let len = len as usize;
708
1.94M
709
1.94M
        // Clear the existing value. This follows from the following rule in the encoding guide[1]:
710
1.94M
        //
711
1.94M
        // > Normally, an encoded message would never have more than one instance of a non-repeated
712
1.94M
        // > field. However, parsers are expected to handle the case in which they do. For numeric
713
1.94M
        // > types and strings, if the same field appears multiple times, the parser accepts the
714
1.94M
        // > last value it sees.
715
1.94M
        //
716
1.94M
        // [1]: https://developers.google.com/protocol-buffers/docs/encoding#optional
717
1.94M
        //
718
1.94M
        // This is intended for A and B both being Bytes so it is zero-copy.
719
1.94M
        // Some combinations of A and B types may cause a double-copy,
720
1.94M
        // in which case merge_one_copy() should be used instead.
721
1.94M
        value.replace_with(buf.copy_to_bytes(len));
722
1.94M
        Ok(())
723
1.94M
    }
724
725
1.92M
    pub(super) fn merge_one_copy(
726
1.92M
        wire_type: WireType,
727
1.92M
        value: &mut impl BytesAdapter,
728
1.92M
        buf: &mut impl Buf,
729
1.92M
        _ctx: DecodeContext,
730
1.92M
    ) -> Result<(), DecodeError> {
731
1.92M
        check_wire_type(WireType::LengthDelimited, wire_type)?;
732
1.92M
        let len = decode_varint(buf)?;
733
1.92M
        if len > buf.remaining() as u64 {
734
374
            return Err(DecodeError::new("buffer underflow"));
735
1.92M
        }
736
1.92M
        let len = len as usize;
737
1.92M
738
1.92M
        // If we must copy, make sure to copy only once.
739
1.92M
        value.replace_with(buf.take(len));
740
1.92M
        Ok(())
741
1.92M
    }
Unexecuted instantiation: prost::encoding::bytes::merge_one_copy::<alloc::vec::Vec<u8>, &mut &mut tonic::codec::buffer::DecodeBuf>
prost::encoding::bytes::merge_one_copy::<alloc::vec::Vec<u8>, &mut &[u8]>
Line
Count
Source
725
1.92M
    pub(super) fn merge_one_copy(
726
1.92M
        wire_type: WireType,
727
1.92M
        value: &mut impl BytesAdapter,
728
1.92M
        buf: &mut impl Buf,
729
1.92M
        _ctx: DecodeContext,
730
1.92M
    ) -> Result<(), DecodeError> {
731
1.92M
        check_wire_type(WireType::LengthDelimited, wire_type)?;
732
1.92M
        let len = decode_varint(buf)?;
733
1.92M
        if len > buf.remaining() as u64 {
734
374
            return Err(DecodeError::new("buffer underflow"));
735
1.92M
        }
736
1.92M
        let len = len as usize;
737
1.92M
738
1.92M
        // If we must copy, make sure to copy only once.
739
1.92M
        value.replace_with(buf.take(len));
740
1.92M
        Ok(())
741
1.92M
    }
Unexecuted instantiation: prost::encoding::bytes::merge_one_copy::<_, _>
742
743
    length_delimited!(impl BytesAdapter);
744
745
    #[cfg(test)]
746
    mod test {
747
        use proptest::prelude::*;
748
749
        use super::super::test::{check_collection_type, check_type};
750
        use super::*;
751
752
        proptest! {
753
            #[test]
754
            fn check_vec(value: Vec<u8>, tag in MIN_TAG..=MAX_TAG) {
755
                super::test::check_type::<Vec<u8>, Vec<u8>>(value, tag, WireType::LengthDelimited,
756
                                                            encode, merge, encoded_len)?;
757
            }
758
759
            #[test]
760
            fn check_bytes(value: Vec<u8>, tag in MIN_TAG..=MAX_TAG) {
761
                let value = Bytes::from(value);
762
                super::test::check_type::<Bytes, Bytes>(value, tag, WireType::LengthDelimited,
763
                                                        encode, merge, encoded_len)?;
764
            }
765
766
            #[test]
767
            fn check_repeated_vec(value: Vec<Vec<u8>>, tag in MIN_TAG..=MAX_TAG) {
768
                super::test::check_collection_type(value, tag, WireType::LengthDelimited,
769
                                                   encode_repeated, merge_repeated,
770
                                                   encoded_len_repeated)?;
771
            }
772
773
            #[test]
774
            fn check_repeated_bytes(value: Vec<Vec<u8>>, tag in MIN_TAG..=MAX_TAG) {
775
                let value = value.into_iter().map(Bytes::from).collect();
776
                super::test::check_collection_type(value, tag, WireType::LengthDelimited,
777
                                                   encode_repeated, merge_repeated,
778
                                                   encoded_len_repeated)?;
779
            }
780
        }
781
    }
782
}
783
784
pub mod message {
785
    use super::*;
786
787
0
    pub fn encode<M>(tag: u32, msg: &M, buf: &mut impl BufMut)
788
0
    where
789
0
        M: Message,
790
0
    {
791
0
        encode_key(tag, WireType::LengthDelimited, buf);
792
0
        encode_varint(msg.encoded_len() as u64, buf);
793
0
        msg.encode_raw(buf);
794
0
    }
Unexecuted instantiation: prost::encoding::message::encode::<prost_types::protobuf::Value, tonic::codec::buffer::EncodeBuf>
Unexecuted instantiation: prost::encoding::message::encode::<prost_types::protobuf::Struct, tonic::codec::buffer::EncodeBuf>
Unexecuted instantiation: prost::encoding::message::encode::<prost_types::protobuf::ListValue, tonic::codec::buffer::EncodeBuf>
Unexecuted instantiation: prost::encoding::message::encode::<ztunnel::inpod::istio::zds::Ack, alloc::vec::Vec<u8>>
Unexecuted instantiation: prost::encoding::message::encode::<_, _>
795
796
1.95M
    pub fn merge<M, B>(
797
1.95M
        wire_type: WireType,
798
1.95M
        msg: &mut M,
799
1.95M
        buf: &mut B,
800
1.95M
        ctx: DecodeContext,
801
1.95M
    ) -> Result<(), DecodeError>
802
1.95M
    where
803
1.95M
        M: Message,
804
1.95M
        B: Buf,
805
1.95M
    {
806
1.95M
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
1.95M
        ctx.limit_reached()?;
808
1.95M
        merge_loop(
809
1.95M
            msg,
810
1.95M
            buf,
811
1.95M
            ctx.enter_recursion(),
812
1.95M
            |msg: &mut M, buf: &mut B, ctx| {
813
888k
                let (tag, wire_type) = decode_key(buf)?;
814
887k
                msg.merge_field(tag, wire_type, buf, ctx)
815
1.95M
            },
Unexecuted instantiation: prost::encoding::message::merge::<ztunnel::inpod::istio::zds::AddWorkload, &mut &[u8]>::{closure#0}
Unexecuted instantiation: prost::encoding::message::merge::<ztunnel::inpod::istio::zds::DelWorkload, &mut &[u8]>::{closure#0}
Unexecuted instantiation: prost::encoding::message::merge::<ztunnel::inpod::istio::zds::KeepWorkload, &mut &[u8]>::{closure#0}
Unexecuted instantiation: prost::encoding::message::merge::<ztunnel::inpod::istio::zds::SnapshotSent, &mut &[u8]>::{closure#0}
Unexecuted instantiation: prost::encoding::message::merge::<ztunnel::inpod::istio::zds::WorkloadInfo, &mut &[u8]>::{closure#0}
Unexecuted instantiation: prost::encoding::message::merge::<_, _>::{closure#0}
prost::encoding::message::merge::<prost_types::protobuf::Any, &mut &[u8]>::{closure#0}
Line
Count
Source
812
36.9k
            |msg: &mut M, buf: &mut B, ctx| {
813
36.9k
                let (tag, wire_type) = decode_key(buf)?;
814
36.8k
                msg.merge_field(tag, wire_type, buf, ctx)
815
36.9k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::StringMatch, &mut &[u8]>::{closure#0}
Line
Count
Source
812
108k
            |msg: &mut M, buf: &mut B, ctx| {
813
108k
                let (tag, wire_type) = decode_key(buf)?;
814
108k
                msg.merge_field(tag, wire_type, buf, ctx)
815
108k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::ServiceAccountMatch, &mut &[u8]>::{closure#0}
Line
Count
Source
812
26.6k
            |msg: &mut M, buf: &mut B, ctx| {
813
26.6k
                let (tag, wire_type) = decode_key(buf)?;
814
26.5k
                msg.merge_field(tag, wire_type, buf, ctx)
815
26.6k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::Rule, &mut &[u8]>::{closure#0}
Line
Count
Source
812
47.9k
            |msg: &mut M, buf: &mut B, ctx| {
813
47.9k
                let (tag, wire_type) = decode_key(buf)?;
814
47.9k
                msg.merge_field(tag, wire_type, buf, ctx)
815
47.9k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::Match, &mut &[u8]>::{closure#0}
Line
Count
Source
812
498k
            |msg: &mut M, buf: &mut B, ctx| {
813
498k
                let (tag, wire_type) = decode_key(buf)?;
814
498k
                msg.merge_field(tag, wire_type, buf, ctx)
815
498k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::Clause, &mut &[u8]>::{closure#0}
Line
Count
Source
812
34.9k
            |msg: &mut M, buf: &mut B, ctx| {
813
34.9k
                let (tag, wire_type) = decode_key(buf)?;
814
34.9k
                msg.merge_field(tag, wire_type, buf, ctx)
815
34.9k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::Address, &mut &[u8]>::{closure#0}
Line
Count
Source
812
13.5k
            |msg: &mut M, buf: &mut B, ctx| {
813
13.5k
                let (tag, wire_type) = decode_key(buf)?;
814
13.4k
                msg.merge_field(tag, wire_type, buf, ctx)
815
13.5k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::GatewayAddress, &mut &[u8]>::{closure#0}
Line
Count
Source
812
13.0k
            |msg: &mut M, buf: &mut B, ctx| {
813
13.0k
                let (tag, wire_type) = decode_key(buf)?;
814
13.0k
                msg.merge_field(tag, wire_type, buf, ctx)
815
13.0k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::NetworkAddress, &mut &[u8]>::{closure#0}
Line
Count
Source
812
66.0k
            |msg: &mut M, buf: &mut B, ctx| {
813
66.0k
                let (tag, wire_type) = decode_key(buf)?;
814
65.9k
                msg.merge_field(tag, wire_type, buf, ctx)
815
66.0k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::ApplicationTunnel, &mut &[u8]>::{closure#0}
Line
Count
Source
812
4.86k
            |msg: &mut M, buf: &mut B, ctx| {
813
4.86k
                let (tag, wire_type) = decode_key(buf)?;
814
4.77k
                msg.merge_field(tag, wire_type, buf, ctx)
815
4.86k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::NamespacedHostname, &mut &[u8]>::{closure#0}
Line
Count
Source
812
6.97k
            |msg: &mut M, buf: &mut B, ctx| {
813
6.97k
                let (tag, wire_type) = decode_key(buf)?;
814
6.89k
                msg.merge_field(tag, wire_type, buf, ctx)
815
6.97k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::Port, &mut &[u8]>::{closure#0}
Line
Count
Source
812
1.53k
            |msg: &mut M, buf: &mut B, ctx| {
813
1.53k
                let (tag, wire_type) = decode_key(buf)?;
814
1.50k
                msg.merge_field(tag, wire_type, buf, ctx)
815
1.53k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::Locality, &mut &[u8]>::{closure#0}
Line
Count
Source
812
7.01k
            |msg: &mut M, buf: &mut B, ctx| {
813
7.01k
                let (tag, wire_type) = decode_key(buf)?;
814
6.96k
                msg.merge_field(tag, wire_type, buf, ctx)
815
7.01k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::PortList, &mut &[u8]>::{closure#0}
Line
Count
Source
812
7.29k
            |msg: &mut M, buf: &mut B, ctx| {
813
7.29k
                let (tag, wire_type) = decode_key(buf)?;
814
7.25k
                msg.merge_field(tag, wire_type, buf, ctx)
815
7.29k
            },
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::Extension, &mut &[u8]>::{closure#0}
Line
Count
Source
812
10.1k
            |msg: &mut M, buf: &mut B, ctx| {
813
10.1k
                let (tag, wire_type) = decode_key(buf)?;
814
10.0k
                msg.merge_field(tag, wire_type, buf, ctx)
815
10.1k
            },
prost::encoding::message::merge::<(), &mut &[u8]>::{closure#0}
Line
Count
Source
812
4.82k
            |msg: &mut M, buf: &mut B, ctx| {
813
4.82k
                let (tag, wire_type) = decode_key(buf)?;
814
4.73k
                msg.merge_field(tag, wire_type, buf, ctx)
815
4.82k
            },
816
1.95M
        )
817
1.95M
    }
Unexecuted instantiation: prost::encoding::message::merge::<ztunnel::inpod::istio::zds::AddWorkload, &mut &[u8]>
Unexecuted instantiation: prost::encoding::message::merge::<ztunnel::inpod::istio::zds::DelWorkload, &mut &[u8]>
Unexecuted instantiation: prost::encoding::message::merge::<ztunnel::inpod::istio::zds::KeepWorkload, &mut &[u8]>
Unexecuted instantiation: prost::encoding::message::merge::<ztunnel::inpod::istio::zds::SnapshotSent, &mut &[u8]>
Unexecuted instantiation: prost::encoding::message::merge::<ztunnel::inpod::istio::zds::WorkloadInfo, &mut &[u8]>
Unexecuted instantiation: prost::encoding::message::merge::<_, _>
prost::encoding::message::merge::<prost_types::protobuf::Any, &mut &[u8]>
Line
Count
Source
796
2.38k
    pub fn merge<M, B>(
797
2.38k
        wire_type: WireType,
798
2.38k
        msg: &mut M,
799
2.38k
        buf: &mut B,
800
2.38k
        ctx: DecodeContext,
801
2.38k
    ) -> Result<(), DecodeError>
802
2.38k
    where
803
2.38k
        M: Message,
804
2.38k
        B: Buf,
805
2.38k
    {
806
2.38k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
2.38k
        ctx.limit_reached()?;
808
2.38k
        merge_loop(
809
2.38k
            msg,
810
2.38k
            buf,
811
2.38k
            ctx.enter_recursion(),
812
2.38k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
2.38k
            },
816
2.38k
        )
817
2.38k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::StringMatch, &mut &[u8]>
Line
Count
Source
796
278k
    pub fn merge<M, B>(
797
278k
        wire_type: WireType,
798
278k
        msg: &mut M,
799
278k
        buf: &mut B,
800
278k
        ctx: DecodeContext,
801
278k
    ) -> Result<(), DecodeError>
802
278k
    where
803
278k
        M: Message,
804
278k
        B: Buf,
805
278k
    {
806
278k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
278k
        ctx.limit_reached()?;
808
278k
        merge_loop(
809
278k
            msg,
810
278k
            buf,
811
278k
            ctx.enter_recursion(),
812
278k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
278k
            },
816
278k
        )
817
278k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::ServiceAccountMatch, &mut &[u8]>
Line
Count
Source
796
10.8k
    pub fn merge<M, B>(
797
10.8k
        wire_type: WireType,
798
10.8k
        msg: &mut M,
799
10.8k
        buf: &mut B,
800
10.8k
        ctx: DecodeContext,
801
10.8k
    ) -> Result<(), DecodeError>
802
10.8k
    where
803
10.8k
        M: Message,
804
10.8k
        B: Buf,
805
10.8k
    {
806
10.8k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
10.8k
        ctx.limit_reached()?;
808
10.8k
        merge_loop(
809
10.8k
            msg,
810
10.8k
            buf,
811
10.8k
            ctx.enter_recursion(),
812
10.8k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
10.8k
            },
816
10.8k
        )
817
10.8k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::Rule, &mut &[u8]>
Line
Count
Source
796
1.37M
    pub fn merge<M, B>(
797
1.37M
        wire_type: WireType,
798
1.37M
        msg: &mut M,
799
1.37M
        buf: &mut B,
800
1.37M
        ctx: DecodeContext,
801
1.37M
    ) -> Result<(), DecodeError>
802
1.37M
    where
803
1.37M
        M: Message,
804
1.37M
        B: Buf,
805
1.37M
    {
806
1.37M
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
1.37M
        ctx.limit_reached()?;
808
1.37M
        merge_loop(
809
1.37M
            msg,
810
1.37M
            buf,
811
1.37M
            ctx.enter_recursion(),
812
1.37M
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
1.37M
            },
816
1.37M
        )
817
1.37M
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::Match, &mut &[u8]>
Line
Count
Source
796
28.6k
    pub fn merge<M, B>(
797
28.6k
        wire_type: WireType,
798
28.6k
        msg: &mut M,
799
28.6k
        buf: &mut B,
800
28.6k
        ctx: DecodeContext,
801
28.6k
    ) -> Result<(), DecodeError>
802
28.6k
    where
803
28.6k
        M: Message,
804
28.6k
        B: Buf,
805
28.6k
    {
806
28.6k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
28.6k
        ctx.limit_reached()?;
808
28.6k
        merge_loop(
809
28.6k
            msg,
810
28.6k
            buf,
811
28.6k
            ctx.enter_recursion(),
812
28.6k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
28.6k
            },
816
28.6k
        )
817
28.6k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::Clause, &mut &[u8]>
Line
Count
Source
796
26.8k
    pub fn merge<M, B>(
797
26.8k
        wire_type: WireType,
798
26.8k
        msg: &mut M,
799
26.8k
        buf: &mut B,
800
26.8k
        ctx: DecodeContext,
801
26.8k
    ) -> Result<(), DecodeError>
802
26.8k
    where
803
26.8k
        M: Message,
804
26.8k
        B: Buf,
805
26.8k
    {
806
26.8k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
26.8k
        ctx.limit_reached()?;
808
26.8k
        merge_loop(
809
26.8k
            msg,
810
26.8k
            buf,
811
26.8k
            ctx.enter_recursion(),
812
26.8k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
26.8k
            },
816
26.8k
        )
817
26.8k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::security::Address, &mut &[u8]>
Line
Count
Source
796
191k
    pub fn merge<M, B>(
797
191k
        wire_type: WireType,
798
191k
        msg: &mut M,
799
191k
        buf: &mut B,
800
191k
        ctx: DecodeContext,
801
191k
    ) -> Result<(), DecodeError>
802
191k
    where
803
191k
        M: Message,
804
191k
        B: Buf,
805
191k
    {
806
191k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
191k
        ctx.limit_reached()?;
808
191k
        merge_loop(
809
191k
            msg,
810
191k
            buf,
811
191k
            ctx.enter_recursion(),
812
191k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
191k
            },
816
191k
        )
817
191k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::GatewayAddress, &mut &[u8]>
Line
Count
Source
796
4.51k
    pub fn merge<M, B>(
797
4.51k
        wire_type: WireType,
798
4.51k
        msg: &mut M,
799
4.51k
        buf: &mut B,
800
4.51k
        ctx: DecodeContext,
801
4.51k
    ) -> Result<(), DecodeError>
802
4.51k
    where
803
4.51k
        M: Message,
804
4.51k
        B: Buf,
805
4.51k
    {
806
4.51k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
4.48k
        ctx.limit_reached()?;
808
4.48k
        merge_loop(
809
4.48k
            msg,
810
4.48k
            buf,
811
4.48k
            ctx.enter_recursion(),
812
4.48k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
4.48k
            },
816
4.48k
        )
817
4.51k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::NetworkAddress, &mut &[u8]>
Line
Count
Source
796
4.22k
    pub fn merge<M, B>(
797
4.22k
        wire_type: WireType,
798
4.22k
        msg: &mut M,
799
4.22k
        buf: &mut B,
800
4.22k
        ctx: DecodeContext,
801
4.22k
    ) -> Result<(), DecodeError>
802
4.22k
    where
803
4.22k
        M: Message,
804
4.22k
        B: Buf,
805
4.22k
    {
806
4.22k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
4.21k
        ctx.limit_reached()?;
808
4.21k
        merge_loop(
809
4.21k
            msg,
810
4.21k
            buf,
811
4.21k
            ctx.enter_recursion(),
812
4.21k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
4.21k
            },
816
4.21k
        )
817
4.22k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::ApplicationTunnel, &mut &[u8]>
Line
Count
Source
796
2.04k
    pub fn merge<M, B>(
797
2.04k
        wire_type: WireType,
798
2.04k
        msg: &mut M,
799
2.04k
        buf: &mut B,
800
2.04k
        ctx: DecodeContext,
801
2.04k
    ) -> Result<(), DecodeError>
802
2.04k
    where
803
2.04k
        M: Message,
804
2.04k
        B: Buf,
805
2.04k
    {
806
2.04k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
2.04k
        ctx.limit_reached()?;
808
2.04k
        merge_loop(
809
2.04k
            msg,
810
2.04k
            buf,
811
2.04k
            ctx.enter_recursion(),
812
2.04k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
2.04k
            },
816
2.04k
        )
817
2.04k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::NamespacedHostname, &mut &[u8]>
Line
Count
Source
796
3.56k
    pub fn merge<M, B>(
797
3.56k
        wire_type: WireType,
798
3.56k
        msg: &mut M,
799
3.56k
        buf: &mut B,
800
3.56k
        ctx: DecodeContext,
801
3.56k
    ) -> Result<(), DecodeError>
802
3.56k
    where
803
3.56k
        M: Message,
804
3.56k
        B: Buf,
805
3.56k
    {
806
3.56k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
3.56k
        ctx.limit_reached()?;
808
3.56k
        merge_loop(
809
3.56k
            msg,
810
3.56k
            buf,
811
3.56k
            ctx.enter_recursion(),
812
3.56k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
3.56k
            },
816
3.56k
        )
817
3.56k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::Port, &mut &[u8]>
Line
Count
Source
796
4.66k
    pub fn merge<M, B>(
797
4.66k
        wire_type: WireType,
798
4.66k
        msg: &mut M,
799
4.66k
        buf: &mut B,
800
4.66k
        ctx: DecodeContext,
801
4.66k
    ) -> Result<(), DecodeError>
802
4.66k
    where
803
4.66k
        M: Message,
804
4.66k
        B: Buf,
805
4.66k
    {
806
4.66k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
4.66k
        ctx.limit_reached()?;
808
4.66k
        merge_loop(
809
4.66k
            msg,
810
4.66k
            buf,
811
4.66k
            ctx.enter_recursion(),
812
4.66k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
4.66k
            },
816
4.66k
        )
817
4.66k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::Locality, &mut &[u8]>
Line
Count
Source
796
1.75k
    pub fn merge<M, B>(
797
1.75k
        wire_type: WireType,
798
1.75k
        msg: &mut M,
799
1.75k
        buf: &mut B,
800
1.75k
        ctx: DecodeContext,
801
1.75k
    ) -> Result<(), DecodeError>
802
1.75k
    where
803
1.75k
        M: Message,
804
1.75k
        B: Buf,
805
1.75k
    {
806
1.75k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
1.74k
        ctx.limit_reached()?;
808
1.74k
        merge_loop(
809
1.74k
            msg,
810
1.74k
            buf,
811
1.74k
            ctx.enter_recursion(),
812
1.74k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
1.74k
            },
816
1.74k
        )
817
1.75k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::PortList, &mut &[u8]>
Line
Count
Source
796
3.93k
    pub fn merge<M, B>(
797
3.93k
        wire_type: WireType,
798
3.93k
        msg: &mut M,
799
3.93k
        buf: &mut B,
800
3.93k
        ctx: DecodeContext,
801
3.93k
    ) -> Result<(), DecodeError>
802
3.93k
    where
803
3.93k
        M: Message,
804
3.93k
        B: Buf,
805
3.93k
    {
806
3.93k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
3.92k
        ctx.limit_reached()?;
808
3.92k
        merge_loop(
809
3.92k
            msg,
810
3.92k
            buf,
811
3.92k
            ctx.enter_recursion(),
812
3.92k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
3.92k
            },
816
3.92k
        )
817
3.93k
    }
prost::encoding::message::merge::<ztunnel::xds::types::istio::workload::Extension, &mut &[u8]>
Line
Count
Source
796
7.62k
    pub fn merge<M, B>(
797
7.62k
        wire_type: WireType,
798
7.62k
        msg: &mut M,
799
7.62k
        buf: &mut B,
800
7.62k
        ctx: DecodeContext,
801
7.62k
    ) -> Result<(), DecodeError>
802
7.62k
    where
803
7.62k
        M: Message,
804
7.62k
        B: Buf,
805
7.62k
    {
806
7.62k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
7.62k
        ctx.limit_reached()?;
808
7.62k
        merge_loop(
809
7.62k
            msg,
810
7.62k
            buf,
811
7.62k
            ctx.enter_recursion(),
812
7.62k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
7.62k
            },
816
7.62k
        )
817
7.62k
    }
prost::encoding::message::merge::<(), &mut &[u8]>
Line
Count
Source
796
8.38k
    pub fn merge<M, B>(
797
8.38k
        wire_type: WireType,
798
8.38k
        msg: &mut M,
799
8.38k
        buf: &mut B,
800
8.38k
        ctx: DecodeContext,
801
8.38k
    ) -> Result<(), DecodeError>
802
8.38k
    where
803
8.38k
        M: Message,
804
8.38k
        B: Buf,
805
8.38k
    {
806
8.38k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
807
8.37k
        ctx.limit_reached()?;
808
8.37k
        merge_loop(
809
8.37k
            msg,
810
8.37k
            buf,
811
8.37k
            ctx.enter_recursion(),
812
8.37k
            |msg: &mut M, buf: &mut B, ctx| {
813
                let (tag, wire_type) = decode_key(buf)?;
814
                msg.merge_field(tag, wire_type, buf, ctx)
815
8.37k
            },
816
8.37k
        )
817
8.38k
    }
818
819
0
    pub fn encode_repeated<M>(tag: u32, messages: &[M], buf: &mut impl BufMut)
820
0
    where
821
0
        M: Message,
822
0
    {
823
0
        for msg in messages {
824
0
            encode(tag, msg, buf);
825
0
        }
826
0
    }
827
828
1.92M
    pub fn merge_repeated<M>(
829
1.92M
        wire_type: WireType,
830
1.92M
        messages: &mut Vec<M>,
831
1.92M
        buf: &mut impl Buf,
832
1.92M
        ctx: DecodeContext,
833
1.92M
    ) -> Result<(), DecodeError>
834
1.92M
    where
835
1.92M
        M: Message + Default,
836
1.92M
    {
837
1.92M
        check_wire_type(WireType::LengthDelimited, wire_type)?;
838
1.91M
        let mut msg = M::default();
839
1.91M
        merge(WireType::LengthDelimited, &mut msg, buf, ctx)?;
840
1.91M
        messages.push(msg);
841
1.91M
        Ok(())
842
1.92M
    }
Unexecuted instantiation: prost::encoding::message::merge_repeated::<_, _>
prost::encoding::message::merge_repeated::<ztunnel::xds::types::istio::security::StringMatch, &mut &[u8]>
Line
Count
Source
828
278k
    pub fn merge_repeated<M>(
829
278k
        wire_type: WireType,
830
278k
        messages: &mut Vec<M>,
831
278k
        buf: &mut impl Buf,
832
278k
        ctx: DecodeContext,
833
278k
    ) -> Result<(), DecodeError>
834
278k
    where
835
278k
        M: Message + Default,
836
278k
    {
837
278k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
838
278k
        let mut msg = M::default();
839
278k
        merge(WireType::LengthDelimited, &mut msg, buf, ctx)?;
840
278k
        messages.push(msg);
841
278k
        Ok(())
842
278k
    }
prost::encoding::message::merge_repeated::<ztunnel::xds::types::istio::security::ServiceAccountMatch, &mut &[u8]>
Line
Count
Source
828
10.8k
    pub fn merge_repeated<M>(
829
10.8k
        wire_type: WireType,
830
10.8k
        messages: &mut Vec<M>,
831
10.8k
        buf: &mut impl Buf,
832
10.8k
        ctx: DecodeContext,
833
10.8k
    ) -> Result<(), DecodeError>
834
10.8k
    where
835
10.8k
        M: Message + Default,
836
10.8k
    {
837
10.8k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
838
10.8k
        let mut msg = M::default();
839
10.8k
        merge(WireType::LengthDelimited, &mut msg, buf, ctx)?;
840
10.6k
        messages.push(msg);
841
10.6k
        Ok(())
842
10.8k
    }
prost::encoding::message::merge_repeated::<ztunnel::xds::types::istio::security::Rule, &mut &[u8]>
Line
Count
Source
828
1.37M
    pub fn merge_repeated<M>(
829
1.37M
        wire_type: WireType,
830
1.37M
        messages: &mut Vec<M>,
831
1.37M
        buf: &mut impl Buf,
832
1.37M
        ctx: DecodeContext,
833
1.37M
    ) -> Result<(), DecodeError>
834
1.37M
    where
835
1.37M
        M: Message + Default,
836
1.37M
    {
837
1.37M
        check_wire_type(WireType::LengthDelimited, wire_type)?;
838
1.37M
        let mut msg = M::default();
839
1.37M
        merge(WireType::LengthDelimited, &mut msg, buf, ctx)?;
840
1.36M
        messages.push(msg);
841
1.36M
        Ok(())
842
1.37M
    }
prost::encoding::message::merge_repeated::<ztunnel::xds::types::istio::security::Match, &mut &[u8]>
Line
Count
Source
828
28.6k
    pub fn merge_repeated<M>(
829
28.6k
        wire_type: WireType,
830
28.6k
        messages: &mut Vec<M>,
831
28.6k
        buf: &mut impl Buf,
832
28.6k
        ctx: DecodeContext,
833
28.6k
    ) -> Result<(), DecodeError>
834
28.6k
    where
835
28.6k
        M: Message + Default,
836
28.6k
    {
837
28.6k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
838
28.6k
        let mut msg = M::default();
839
28.6k
        merge(WireType::LengthDelimited, &mut msg, buf, ctx)?;
840
26.8k
        messages.push(msg);
841
26.8k
        Ok(())
842
28.6k
    }
prost::encoding::message::merge_repeated::<ztunnel::xds::types::istio::security::Clause, &mut &[u8]>
Line
Count
Source
828
26.8k
    pub fn merge_repeated<M>(
829
26.8k
        wire_type: WireType,
830
26.8k
        messages: &mut Vec<M>,
831
26.8k
        buf: &mut impl Buf,
832
26.8k
        ctx: DecodeContext,
833
26.8k
    ) -> Result<(), DecodeError>
834
26.8k
    where
835
26.8k
        M: Message + Default,
836
26.8k
    {
837
26.8k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
838
26.8k
        let mut msg = M::default();
839
26.8k
        merge(WireType::LengthDelimited, &mut msg, buf, ctx)?;
840
24.6k
        messages.push(msg);
841
24.6k
        Ok(())
842
26.8k
    }
prost::encoding::message::merge_repeated::<ztunnel::xds::types::istio::security::Address, &mut &[u8]>
Line
Count
Source
828
191k
    pub fn merge_repeated<M>(
829
191k
        wire_type: WireType,
830
191k
        messages: &mut Vec<M>,
831
191k
        buf: &mut impl Buf,
832
191k
        ctx: DecodeContext,
833
191k
    ) -> Result<(), DecodeError>
834
191k
    where
835
191k
        M: Message + Default,
836
191k
    {
837
191k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
838
191k
        let mut msg = M::default();
839
191k
        merge(WireType::LengthDelimited, &mut msg, buf, ctx)?;
840
190k
        messages.push(msg);
841
190k
        Ok(())
842
191k
    }
prost::encoding::message::merge_repeated::<ztunnel::xds::types::istio::workload::Port, &mut &[u8]>
Line
Count
Source
828
4.66k
    pub fn merge_repeated<M>(
829
4.66k
        wire_type: WireType,
830
4.66k
        messages: &mut Vec<M>,
831
4.66k
        buf: &mut impl Buf,
832
4.66k
        ctx: DecodeContext,
833
4.66k
    ) -> Result<(), DecodeError>
834
4.66k
    where
835
4.66k
        M: Message + Default,
836
4.66k
    {
837
4.66k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
838
4.66k
        let mut msg = M::default();
839
4.66k
        merge(WireType::LengthDelimited, &mut msg, buf, ctx)?;
840
4.52k
        messages.push(msg);
841
4.52k
        Ok(())
842
4.66k
    }
prost::encoding::message::merge_repeated::<ztunnel::xds::types::istio::workload::Extension, &mut &[u8]>
Line
Count
Source
828
7.62k
    pub fn merge_repeated<M>(
829
7.62k
        wire_type: WireType,
830
7.62k
        messages: &mut Vec<M>,
831
7.62k
        buf: &mut impl Buf,
832
7.62k
        ctx: DecodeContext,
833
7.62k
    ) -> Result<(), DecodeError>
834
7.62k
    where
835
7.62k
        M: Message + Default,
836
7.62k
    {
837
7.62k
        check_wire_type(WireType::LengthDelimited, wire_type)?;
838
7.62k
        let mut msg = M::default();
839
7.62k
        merge(WireType::LengthDelimited, &mut msg, buf, ctx)?;
840
7.17k
        messages.push(msg);
841
7.17k
        Ok(())
842
7.62k
    }
843
844
    #[inline]
845
0
    pub fn encoded_len<M>(tag: u32, msg: &M) -> usize
846
0
    where
847
0
        M: Message,
848
0
    {
849
0
        let len = msg.encoded_len();
850
0
        key_len(tag) + encoded_len_varint(len as u64) + len
851
0
    }
Unexecuted instantiation: prost::encoding::message::encoded_len::<prost_types::protobuf::Value>
Unexecuted instantiation: prost::encoding::message::encoded_len::<prost_types::protobuf::Struct>
Unexecuted instantiation: prost::encoding::message::encoded_len::<prost_types::protobuf::ListValue>
Unexecuted instantiation: prost::encoding::message::encoded_len::<ztunnel::inpod::istio::zds::Ack>
Unexecuted instantiation: prost::encoding::message::encoded_len::<_>
852
853
    #[inline]
854
0
    pub fn encoded_len_repeated<M>(tag: u32, messages: &[M]) -> usize
855
0
    where
856
0
        M: Message,
857
0
    {
858
0
        key_len(tag) * messages.len()
859
0
            + messages
860
0
                .iter()
861
0
                .map(Message::encoded_len)
862
0
                .map(|len| len + encoded_len_varint(len as u64))
Unexecuted instantiation: prost::encoding::message::encoded_len_repeated::<prost_types::protobuf::Value>::{closure#0}
Unexecuted instantiation: prost::encoding::message::encoded_len_repeated::<_>::{closure#0}
863
0
                .sum::<usize>()
864
0
    }
Unexecuted instantiation: prost::encoding::message::encoded_len_repeated::<prost_types::protobuf::Value>
Unexecuted instantiation: prost::encoding::message::encoded_len_repeated::<_>
865
}
866
867
pub mod group {
868
    use super::*;
869
870
0
    pub fn encode<M>(tag: u32, msg: &M, buf: &mut impl BufMut)
871
0
    where
872
0
        M: Message,
873
0
    {
874
0
        encode_key(tag, WireType::StartGroup, buf);
875
0
        msg.encode_raw(buf);
876
0
        encode_key(tag, WireType::EndGroup, buf);
877
0
    }
878
879
0
    pub fn merge<M>(
880
0
        tag: u32,
881
0
        wire_type: WireType,
882
0
        msg: &mut M,
883
0
        buf: &mut impl Buf,
884
0
        ctx: DecodeContext,
885
0
    ) -> Result<(), DecodeError>
886
0
    where
887
0
        M: Message,
888
0
    {
889
0
        check_wire_type(WireType::StartGroup, wire_type)?;
890
891
0
        ctx.limit_reached()?;
892
        loop {
893
0
            let (field_tag, field_wire_type) = decode_key(buf)?;
894
0
            if field_wire_type == WireType::EndGroup {
895
0
                if field_tag != tag {
896
0
                    return Err(DecodeError::new("unexpected end group tag"));
897
0
                }
898
0
                return Ok(());
899
0
            }
900
0
901
0
            M::merge_field(msg, field_tag, field_wire_type, buf, ctx.enter_recursion())?;
902
        }
903
0
    }
904
905
0
    pub fn encode_repeated<M>(tag: u32, messages: &[M], buf: &mut impl BufMut)
906
0
    where
907
0
        M: Message,
908
0
    {
909
0
        for msg in messages {
910
0
            encode(tag, msg, buf);
911
0
        }
912
0
    }
913
914
0
    pub fn merge_repeated<M>(
915
0
        tag: u32,
916
0
        wire_type: WireType,
917
0
        messages: &mut Vec<M>,
918
0
        buf: &mut impl Buf,
919
0
        ctx: DecodeContext,
920
0
    ) -> Result<(), DecodeError>
921
0
    where
922
0
        M: Message + Default,
923
0
    {
924
0
        check_wire_type(WireType::StartGroup, wire_type)?;
925
0
        let mut msg = M::default();
926
0
        merge(tag, WireType::StartGroup, &mut msg, buf, ctx)?;
927
0
        messages.push(msg);
928
0
        Ok(())
929
0
    }
930
931
    #[inline]
932
0
    pub fn encoded_len<M>(tag: u32, msg: &M) -> usize
933
0
    where
934
0
        M: Message,
935
0
    {
936
0
        2 * key_len(tag) + msg.encoded_len()
937
0
    }
938
939
    #[inline]
940
0
    pub fn encoded_len_repeated<M>(tag: u32, messages: &[M]) -> usize
941
0
    where
942
0
        M: Message,
943
0
    {
944
0
        2 * key_len(tag) * messages.len() + messages.iter().map(Message::encoded_len).sum::<usize>()
945
0
    }
946
}
947
948
/// Rust doesn't have a `Map` trait, so macros are currently the best way to be
949
/// generic over `HashMap` and `BTreeMap`.
950
macro_rules! map {
951
    ($map_ty:ident) => {
952
        use crate::encoding::*;
953
        use core::hash::Hash;
954
955
        /// Generic protobuf map encode function.
956
0
        pub fn encode<K, V, B, KE, KL, VE, VL>(
957
0
            key_encode: KE,
958
0
            key_encoded_len: KL,
959
0
            val_encode: VE,
960
0
            val_encoded_len: VL,
961
0
            tag: u32,
962
0
            values: &$map_ty<K, V>,
963
0
            buf: &mut B,
964
0
        ) where
965
0
            K: Default + Eq + Hash + Ord,
966
0
            V: Default + PartialEq,
967
0
            B: BufMut,
968
0
            KE: Fn(u32, &K, &mut B),
969
0
            KL: Fn(u32, &K) -> usize,
970
0
            VE: Fn(u32, &V, &mut B),
971
0
            VL: Fn(u32, &V) -> usize,
972
0
        {
973
0
            encode_with_default(
974
0
                key_encode,
975
0
                key_encoded_len,
976
0
                val_encode,
977
0
                val_encoded_len,
978
0
                &V::default(),
979
0
                tag,
980
0
                values,
981
0
                buf,
982
0
            )
983
0
        }
Unexecuted instantiation: prost::encoding::btree_map::encode::<alloc::string::String, prost_types::protobuf::Value, tonic::codec::buffer::EncodeBuf, prost::encoding::string::encode<tonic::codec::buffer::EncodeBuf>, prost::encoding::string::encoded_len, prost::encoding::message::encode<prost_types::protobuf::Value, tonic::codec::buffer::EncodeBuf>, prost::encoding::message::encoded_len<prost_types::protobuf::Value>>
Unexecuted instantiation: prost::encoding::hash_map::encode::<_, _, _, _, _, _, _>
Unexecuted instantiation: prost::encoding::btree_map::encode::<_, _, _, _, _, _, _>
984
985
        /// Generic protobuf map merge function.
986
128k
        pub fn merge<K, V, B, KM, VM>(
987
128k
            key_merge: KM,
988
128k
            val_merge: VM,
989
128k
            values: &mut $map_ty<K, V>,
990
128k
            buf: &mut B,
991
128k
            ctx: DecodeContext,
992
128k
        ) -> Result<(), DecodeError>
993
128k
        where
994
128k
            K: Default + Eq + Hash + Ord,
995
128k
            V: Default,
996
128k
            B: Buf,
997
128k
            KM: Fn(WireType, &mut K, &mut B, DecodeContext) -> Result<(), DecodeError>,
998
128k
            VM: Fn(WireType, &mut V, &mut B, DecodeContext) -> Result<(), DecodeError>,
999
128k
        {
1000
128k
            merge_with_default(key_merge, val_merge, V::default(), values, buf, ctx)
1001
128k
        }
Unexecuted instantiation: prost::encoding::hash_map::merge::<_, _, _, _, _>
Unexecuted instantiation: prost::encoding::btree_map::merge::<_, _, _, _, _>
prost::encoding::hash_map::merge::<alloc::string::String, ztunnel::xds::types::istio::workload::PortList, &mut &[u8], prost::encoding::string::merge<&mut &[u8]>, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::PortList, &mut &[u8]>>
Line
Count
Source
986
128k
        pub fn merge<K, V, B, KM, VM>(
987
128k
            key_merge: KM,
988
128k
            val_merge: VM,
989
128k
            values: &mut $map_ty<K, V>,
990
128k
            buf: &mut B,
991
128k
            ctx: DecodeContext,
992
128k
        ) -> Result<(), DecodeError>
993
128k
        where
994
128k
            K: Default + Eq + Hash + Ord,
995
128k
            V: Default,
996
128k
            B: Buf,
997
128k
            KM: Fn(WireType, &mut K, &mut B, DecodeContext) -> Result<(), DecodeError>,
998
128k
            VM: Fn(WireType, &mut V, &mut B, DecodeContext) -> Result<(), DecodeError>,
999
128k
        {
1000
128k
            merge_with_default(key_merge, val_merge, V::default(), values, buf, ctx)
1001
128k
        }
1002
1003
        /// Generic protobuf map encode function.
1004
0
        pub fn encoded_len<K, V, KL, VL>(
1005
0
            key_encoded_len: KL,
1006
0
            val_encoded_len: VL,
1007
0
            tag: u32,
1008
0
            values: &$map_ty<K, V>,
1009
0
        ) -> usize
1010
0
        where
1011
0
            K: Default + Eq + Hash + Ord,
1012
0
            V: Default + PartialEq,
1013
0
            KL: Fn(u32, &K) -> usize,
1014
0
            VL: Fn(u32, &V) -> usize,
1015
0
        {
1016
0
            encoded_len_with_default(key_encoded_len, val_encoded_len, &V::default(), tag, values)
1017
0
        }
Unexecuted instantiation: prost::encoding::btree_map::encoded_len::<alloc::string::String, prost_types::protobuf::Value, prost::encoding::string::encoded_len, prost::encoding::message::encoded_len<prost_types::protobuf::Value>>
Unexecuted instantiation: prost::encoding::hash_map::encoded_len::<_, _, _, _>
Unexecuted instantiation: prost::encoding::btree_map::encoded_len::<_, _, _, _>
1018
1019
        /// Generic protobuf map encode function with an overridden value default.
1020
        ///
1021
        /// This is necessary because enumeration values can have a default value other
1022
        /// than 0 in proto2.
1023
0
        pub fn encode_with_default<K, V, B, KE, KL, VE, VL>(
1024
0
            key_encode: KE,
1025
0
            key_encoded_len: KL,
1026
0
            val_encode: VE,
1027
0
            val_encoded_len: VL,
1028
0
            val_default: &V,
1029
0
            tag: u32,
1030
0
            values: &$map_ty<K, V>,
1031
0
            buf: &mut B,
1032
0
        ) where
1033
0
            K: Default + Eq + Hash + Ord,
1034
0
            V: PartialEq,
1035
0
            B: BufMut,
1036
0
            KE: Fn(u32, &K, &mut B),
1037
0
            KL: Fn(u32, &K) -> usize,
1038
0
            VE: Fn(u32, &V, &mut B),
1039
0
            VL: Fn(u32, &V) -> usize,
1040
0
        {
1041
0
            for (key, val) in values.iter() {
1042
0
                let skip_key = key == &K::default();
1043
0
                let skip_val = val == val_default;
1044
1045
0
                let len = (if skip_key { 0 } else { key_encoded_len(1, key) })
1046
0
                    + (if skip_val { 0 } else { val_encoded_len(2, val) });
1047
1048
0
                encode_key(tag, WireType::LengthDelimited, buf);
1049
0
                encode_varint(len as u64, buf);
1050
0
                if !skip_key {
1051
0
                    key_encode(1, key, buf);
1052
0
                }
1053
0
                if !skip_val {
1054
0
                    val_encode(2, val, buf);
1055
0
                }
1056
            }
1057
0
        }
Unexecuted instantiation: prost::encoding::btree_map::encode_with_default::<alloc::string::String, prost_types::protobuf::Value, tonic::codec::buffer::EncodeBuf, prost::encoding::string::encode<tonic::codec::buffer::EncodeBuf>, prost::encoding::string::encoded_len, prost::encoding::message::encode<prost_types::protobuf::Value, tonic::codec::buffer::EncodeBuf>, prost::encoding::message::encoded_len<prost_types::protobuf::Value>>
Unexecuted instantiation: prost::encoding::hash_map::encode_with_default::<_, _, _, _, _, _, _>
Unexecuted instantiation: prost::encoding::btree_map::encode_with_default::<_, _, _, _, _, _, _>
1058
1059
        /// Generic protobuf map merge function with an overridden value default.
1060
        ///
1061
        /// This is necessary because enumeration values can have a default value other
1062
        /// than 0 in proto2.
1063
128k
        pub fn merge_with_default<K, V, B, KM, VM>(
1064
128k
            key_merge: KM,
1065
128k
            val_merge: VM,
1066
128k
            val_default: V,
1067
128k
            values: &mut $map_ty<K, V>,
1068
128k
            buf: &mut B,
1069
128k
            ctx: DecodeContext,
1070
128k
        ) -> Result<(), DecodeError>
1071
128k
        where
1072
128k
            K: Default + Eq + Hash + Ord,
1073
128k
            B: Buf,
1074
128k
            KM: Fn(WireType, &mut K, &mut B, DecodeContext) -> Result<(), DecodeError>,
1075
128k
            VM: Fn(WireType, &mut V, &mut B, DecodeContext) -> Result<(), DecodeError>,
1076
128k
        {
1077
128k
            let mut key = Default::default();
1078
128k
            let mut val = val_default;
1079
128k
            ctx.limit_reached()?;
1080
128k
            merge_loop(
1081
128k
                &mut (&mut key, &mut val),
1082
128k
                buf,
1083
128k
                ctx.enter_recursion(),
1084
132k
                |&mut (ref mut key, ref mut val), buf, ctx| {
1085
132k
                    let (tag, wire_type) = decode_key(buf)?;
1086
132k
                    match tag {
1087
121k
                        1 => key_merge(wire_type, key, buf, ctx),
1088
3.93k
                        2 => val_merge(wire_type, val, buf, ctx),
1089
6.81k
                        _ => skip_field(wire_type, tag, buf, ctx),
1090
                    }
1091
132k
                },
Unexecuted instantiation: prost::encoding::hash_map::merge_with_default::<_, _, _, _, _>::{closure#0}
Unexecuted instantiation: prost::encoding::btree_map::merge_with_default::<_, _, _, _, _>::{closure#0}
prost::encoding::hash_map::merge_with_default::<alloc::string::String, ztunnel::xds::types::istio::workload::PortList, &mut &[u8], prost::encoding::string::merge<&mut &[u8]>, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::PortList, &mut &[u8]>>::{closure#0}
Line
Count
Source
1084
132k
                |&mut (ref mut key, ref mut val), buf, ctx| {
1085
132k
                    let (tag, wire_type) = decode_key(buf)?;
1086
132k
                    match tag {
1087
121k
                        1 => key_merge(wire_type, key, buf, ctx),
1088
3.93k
                        2 => val_merge(wire_type, val, buf, ctx),
1089
6.81k
                        _ => skip_field(wire_type, tag, buf, ctx),
1090
                    }
1091
132k
                },
1092
128k
            )?;
1093
128k
            values.insert(key, val);
1094
128k
1095
128k
            Ok(())
1096
128k
        }
Unexecuted instantiation: prost::encoding::hash_map::merge_with_default::<_, _, _, _, _>
Unexecuted instantiation: prost::encoding::btree_map::merge_with_default::<_, _, _, _, _>
prost::encoding::hash_map::merge_with_default::<alloc::string::String, ztunnel::xds::types::istio::workload::PortList, &mut &[u8], prost::encoding::string::merge<&mut &[u8]>, prost::encoding::message::merge<ztunnel::xds::types::istio::workload::PortList, &mut &[u8]>>
Line
Count
Source
1063
128k
        pub fn merge_with_default<K, V, B, KM, VM>(
1064
128k
            key_merge: KM,
1065
128k
            val_merge: VM,
1066
128k
            val_default: V,
1067
128k
            values: &mut $map_ty<K, V>,
1068
128k
            buf: &mut B,
1069
128k
            ctx: DecodeContext,
1070
128k
        ) -> Result<(), DecodeError>
1071
128k
        where
1072
128k
            K: Default + Eq + Hash + Ord,
1073
128k
            B: Buf,
1074
128k
            KM: Fn(WireType, &mut K, &mut B, DecodeContext) -> Result<(), DecodeError>,
1075
128k
            VM: Fn(WireType, &mut V, &mut B, DecodeContext) -> Result<(), DecodeError>,
1076
128k
        {
1077
128k
            let mut key = Default::default();
1078
128k
            let mut val = val_default;
1079
128k
            ctx.limit_reached()?;
1080
128k
            merge_loop(
1081
128k
                &mut (&mut key, &mut val),
1082
128k
                buf,
1083
128k
                ctx.enter_recursion(),
1084
128k
                |&mut (ref mut key, ref mut val), buf, ctx| {
1085
                    let (tag, wire_type) = decode_key(buf)?;
1086
                    match tag {
1087
                        1 => key_merge(wire_type, key, buf, ctx),
1088
                        2 => val_merge(wire_type, val, buf, ctx),
1089
                        _ => skip_field(wire_type, tag, buf, ctx),
1090
                    }
1091
128k
                },
1092
128k
            )?;
1093
128k
            values.insert(key, val);
1094
128k
1095
128k
            Ok(())
1096
128k
        }
1097
1098
        /// Generic protobuf map encode function with an overridden value default.
1099
        ///
1100
        /// This is necessary because enumeration values can have a default value other
1101
        /// than 0 in proto2.
1102
0
        pub fn encoded_len_with_default<K, V, KL, VL>(
1103
0
            key_encoded_len: KL,
1104
0
            val_encoded_len: VL,
1105
0
            val_default: &V,
1106
0
            tag: u32,
1107
0
            values: &$map_ty<K, V>,
1108
0
        ) -> usize
1109
0
        where
1110
0
            K: Default + Eq + Hash + Ord,
1111
0
            V: PartialEq,
1112
0
            KL: Fn(u32, &K) -> usize,
1113
0
            VL: Fn(u32, &V) -> usize,
1114
0
        {
1115
0
            key_len(tag) * values.len()
1116
0
                + values
1117
0
                    .iter()
1118
0
                    .map(|(key, val)| {
1119
0
                        let len = (if key == &K::default() {
1120
0
                            0
1121
                        } else {
1122
0
                            key_encoded_len(1, key)
1123
0
                        }) + (if val == val_default {
1124
0
                            0
1125
                        } else {
1126
0
                            val_encoded_len(2, val)
1127
                        });
1128
0
                        encoded_len_varint(len as u64) + len
1129
0
                    })
Unexecuted instantiation: prost::encoding::btree_map::encoded_len_with_default::<alloc::string::String, prost_types::protobuf::Value, prost::encoding::string::encoded_len, prost::encoding::message::encoded_len<prost_types::protobuf::Value>>::{closure#0}
Unexecuted instantiation: prost::encoding::hash_map::encoded_len_with_default::<_, _, _, _>::{closure#0}
Unexecuted instantiation: prost::encoding::btree_map::encoded_len_with_default::<_, _, _, _>::{closure#0}
1130
0
                    .sum::<usize>()
1131
0
        }
Unexecuted instantiation: prost::encoding::btree_map::encoded_len_with_default::<alloc::string::String, prost_types::protobuf::Value, prost::encoding::string::encoded_len, prost::encoding::message::encoded_len<prost_types::protobuf::Value>>
Unexecuted instantiation: prost::encoding::hash_map::encoded_len_with_default::<_, _, _, _>
Unexecuted instantiation: prost::encoding::btree_map::encoded_len_with_default::<_, _, _, _>
1132
    };
1133
}
1134
1135
#[cfg(feature = "std")]
1136
pub mod hash_map {
1137
    use std::collections::HashMap;
1138
    map!(HashMap);
1139
}
1140
1141
pub mod btree_map {
1142
    map!(BTreeMap);
1143
}
1144
1145
#[cfg(test)]
1146
mod test {
1147
    #[cfg(not(feature = "std"))]
1148
    use alloc::string::ToString;
1149
    use core::borrow::Borrow;
1150
    use core::fmt::Debug;
1151
1152
    use ::bytes::BytesMut;
1153
    use proptest::{prelude::*, test_runner::TestCaseResult};
1154
1155
    use super::*;
1156
1157
    pub fn check_type<T, B>(
1158
        value: T,
1159
        tag: u32,
1160
        wire_type: WireType,
1161
        encode: fn(u32, &B, &mut BytesMut),
1162
        merge: fn(WireType, &mut T, &mut Bytes, DecodeContext) -> Result<(), DecodeError>,
1163
        encoded_len: fn(u32, &B) -> usize,
1164
    ) -> TestCaseResult
1165
    where
1166
        T: Debug + Default + PartialEq + Borrow<B>,
1167
        B: ?Sized,
1168
    {
1169
        prop_assume!((MIN_TAG..=MAX_TAG).contains(&tag));
1170
1171
        let expected_len = encoded_len(tag, value.borrow());
1172
1173
        let mut buf = BytesMut::with_capacity(expected_len);
1174
        encode(tag, value.borrow(), &mut buf);
1175
1176
        let mut buf = buf.freeze();
1177
1178
        prop_assert_eq!(
1179
            buf.remaining(),
1180
            expected_len,
1181
            "encoded_len wrong; expected: {}, actual: {}",
1182
            expected_len,
1183
            buf.remaining()
1184
        );
1185
1186
        if !buf.has_remaining() {
1187
            // Short circuit for empty packed values.
1188
            return Ok(());
1189
        }
1190
1191
        let (decoded_tag, decoded_wire_type) =
1192
            decode_key(&mut buf).map_err(|error| TestCaseError::fail(error.to_string()))?;
1193
        prop_assert_eq!(
1194
            tag,
1195
            decoded_tag,
1196
            "decoded tag does not match; expected: {}, actual: {}",
1197
            tag,
1198
            decoded_tag
1199
        );
1200
1201
        prop_assert_eq!(
1202
            wire_type,
1203
            decoded_wire_type,
1204
            "decoded wire type does not match; expected: {:?}, actual: {:?}",
1205
            wire_type,
1206
            decoded_wire_type,
1207
        );
1208
1209
        match wire_type {
1210
            WireType::SixtyFourBit if buf.remaining() != 8 => Err(TestCaseError::fail(format!(
1211
                "64bit wire type illegal remaining: {}, tag: {}",
1212
                buf.remaining(),
1213
                tag
1214
            ))),
1215
            WireType::ThirtyTwoBit if buf.remaining() != 4 => Err(TestCaseError::fail(format!(
1216
                "32bit wire type illegal remaining: {}, tag: {}",
1217
                buf.remaining(),
1218
                tag
1219
            ))),
1220
            _ => Ok(()),
1221
        }?;
1222
1223
        let mut roundtrip_value = T::default();
1224
        merge(
1225
            wire_type,
1226
            &mut roundtrip_value,
1227
            &mut buf,
1228
            DecodeContext::default(),
1229
        )
1230
        .map_err(|error| TestCaseError::fail(error.to_string()))?;
1231
1232
        prop_assert!(
1233
            !buf.has_remaining(),
1234
            "expected buffer to be empty, remaining: {}",
1235
            buf.remaining()
1236
        );
1237
1238
        prop_assert_eq!(value, roundtrip_value);
1239
1240
        Ok(())
1241
    }
1242
1243
    pub fn check_collection_type<T, B, E, M, L>(
1244
        value: T,
1245
        tag: u32,
1246
        wire_type: WireType,
1247
        encode: E,
1248
        mut merge: M,
1249
        encoded_len: L,
1250
    ) -> TestCaseResult
1251
    where
1252
        T: Debug + Default + PartialEq + Borrow<B>,
1253
        B: ?Sized,
1254
        E: FnOnce(u32, &B, &mut BytesMut),
1255
        M: FnMut(WireType, &mut T, &mut Bytes, DecodeContext) -> Result<(), DecodeError>,
1256
        L: FnOnce(u32, &B) -> usize,
1257
    {
1258
        prop_assume!((MIN_TAG..=MAX_TAG).contains(&tag));
1259
1260
        let expected_len = encoded_len(tag, value.borrow());
1261
1262
        let mut buf = BytesMut::with_capacity(expected_len);
1263
        encode(tag, value.borrow(), &mut buf);
1264
1265
        let mut buf = buf.freeze();
1266
1267
        prop_assert_eq!(
1268
            buf.remaining(),
1269
            expected_len,
1270
            "encoded_len wrong; expected: {}, actual: {}",
1271
            expected_len,
1272
            buf.remaining()
1273
        );
1274
1275
        let mut roundtrip_value = Default::default();
1276
        while buf.has_remaining() {
1277
            let (decoded_tag, decoded_wire_type) =
1278
                decode_key(&mut buf).map_err(|error| TestCaseError::fail(error.to_string()))?;
1279
1280
            prop_assert_eq!(
1281
                tag,
1282
                decoded_tag,
1283
                "decoded tag does not match; expected: {}, actual: {}",
1284
                tag,
1285
                decoded_tag
1286
            );
1287
1288
            prop_assert_eq!(
1289
                wire_type,
1290
                decoded_wire_type,
1291
                "decoded wire type does not match; expected: {:?}, actual: {:?}",
1292
                wire_type,
1293
                decoded_wire_type
1294
            );
1295
1296
            merge(
1297
                wire_type,
1298
                &mut roundtrip_value,
1299
                &mut buf,
1300
                DecodeContext::default(),
1301
            )
1302
            .map_err(|error| TestCaseError::fail(error.to_string()))?;
1303
        }
1304
1305
        prop_assert_eq!(value, roundtrip_value);
1306
1307
        Ok(())
1308
    }
1309
1310
    #[test]
1311
    fn string_merge_invalid_utf8() {
1312
        let mut s = String::new();
1313
        let buf = b"\x02\x80\x80";
1314
1315
        let r = string::merge(
1316
            WireType::LengthDelimited,
1317
            &mut s,
1318
            &mut &buf[..],
1319
            DecodeContext::default(),
1320
        );
1321
        r.expect_err("must be an error");
1322
        assert!(s.is_empty());
1323
    }
1324
1325
    /// This big bowl o' macro soup generates an encoding property test for each combination of map
1326
    /// type, scalar map key, and value type.
1327
    /// TODO: these tests take a long time to compile, can this be improved?
1328
    #[cfg(feature = "std")]
1329
    macro_rules! map_tests {
1330
        (keys: $keys:tt,
1331
         vals: $vals:tt) => {
1332
            mod hash_map {
1333
                map_tests!(@private HashMap, hash_map, $keys, $vals);
1334
            }
1335
            mod btree_map {
1336
                map_tests!(@private BTreeMap, btree_map, $keys, $vals);
1337
            }
1338
        };
1339
1340
        (@private $map_type:ident,
1341
                  $mod_name:ident,
1342
                  [$(($key_ty:ty, $key_proto:ident)),*],
1343
                  $vals:tt) => {
1344
            $(
1345
                mod $key_proto {
1346
                    use std::collections::$map_type;
1347
1348
                    use proptest::prelude::*;
1349
1350
                    use crate::encoding::*;
1351
                    use crate::encoding::test::check_collection_type;
1352
1353
                    map_tests!(@private $map_type, $mod_name, ($key_ty, $key_proto), $vals);
1354
                }
1355
            )*
1356
        };
1357
1358
        (@private $map_type:ident,
1359
                  $mod_name:ident,
1360
                  ($key_ty:ty, $key_proto:ident),
1361
                  [$(($val_ty:ty, $val_proto:ident)),*]) => {
1362
            $(
1363
                proptest! {
1364
                    #[test]
1365
                    fn $val_proto(values: $map_type<$key_ty, $val_ty>, tag in MIN_TAG..=MAX_TAG) {
1366
                        check_collection_type(values, tag, WireType::LengthDelimited,
1367
                                              |tag, values, buf| {
1368
                                                  $mod_name::encode($key_proto::encode,
1369
                                                                    $key_proto::encoded_len,
1370
                                                                    $val_proto::encode,
1371
                                                                    $val_proto::encoded_len,
1372
                                                                    tag,
1373
                                                                    values,
1374
                                                                    buf)
1375
                                              },
1376
                                              |wire_type, values, buf, ctx| {
1377
                                                  check_wire_type(WireType::LengthDelimited, wire_type)?;
1378
                                                  $mod_name::merge($key_proto::merge,
1379
                                                                   $val_proto::merge,
1380
                                                                   values,
1381
                                                                   buf,
1382
                                                                   ctx)
1383
                                              },
1384
                                              |tag, values| {
1385
                                                  $mod_name::encoded_len($key_proto::encoded_len,
1386
                                                                         $val_proto::encoded_len,
1387
                                                                         tag,
1388
                                                                         values)
1389
                                              })?;
1390
                    }
1391
                }
1392
             )*
1393
        };
1394
    }
1395
1396
    #[cfg(feature = "std")]
1397
    map_tests!(keys: [
1398
        (i32, int32),
1399
        (i64, int64),
1400
        (u32, uint32),
1401
        (u64, uint64),
1402
        (i32, sint32),
1403
        (i64, sint64),
1404
        (u32, fixed32),
1405
        (u64, fixed64),
1406
        (i32, sfixed32),
1407
        (i64, sfixed64),
1408
        (bool, bool),
1409
        (String, string)
1410
    ],
1411
    vals: [
1412
        (f32, float),
1413
        (f64, double),
1414
        (i32, int32),
1415
        (i64, int64),
1416
        (u32, uint32),
1417
        (u64, uint64),
1418
        (i32, sint32),
1419
        (i64, sint64),
1420
        (u32, fixed32),
1421
        (u64, fixed64),
1422
        (i32, sfixed32),
1423
        (i64, sfixed64),
1424
        (bool, bool),
1425
        (String, string),
1426
        (Vec<u8>, bytes)
1427
    ]);
1428
}