/rust/registry/src/index.crates.io-6f17d22bba15001f/protobuf-2.28.0/src/rt.rs
Line | Count | Source (jump to first uncovered line) |
1 | | //! Functions used by generated protobuf code. |
2 | | //! Should not be used by programs written by hands. |
3 | | |
4 | | use std::collections::HashMap; |
5 | | use std::default::Default; |
6 | | use std::hash::Hash; |
7 | | |
8 | | #[cfg(feature = "bytes")] |
9 | | use bytes::Bytes; |
10 | | |
11 | | #[cfg(feature = "bytes")] |
12 | | use crate::chars::Chars; |
13 | | use crate::coded_input_stream::CodedInputStream; |
14 | | use crate::coded_output_stream::CodedOutputStream; |
15 | | use crate::enums::ProtobufEnum; |
16 | | use crate::error::ProtobufError; |
17 | | use crate::error::ProtobufResult; |
18 | | use crate::error::WireError; |
19 | | pub use crate::lazy_v2::LazyV2; |
20 | | use crate::message::*; |
21 | | use crate::repeated::RepeatedField; |
22 | | use crate::singular::SingularField; |
23 | | use crate::singular::SingularPtrField; |
24 | | use crate::types::*; |
25 | | use crate::unknown::UnknownFields; |
26 | | use crate::wire_format; |
27 | | use crate::wire_format::WireType; |
28 | | use crate::zigzag::*; |
29 | | |
30 | | /// Given `u64` value compute varint encoded length. |
31 | 0 | pub fn compute_raw_varint64_size(value: u64) -> u32 { |
32 | 0 | if (value & (0xffffffffffffffffu64 << 7)) == 0 { |
33 | 0 | return 1; |
34 | 0 | } |
35 | 0 | if (value & (0xffffffffffffffffu64 << 14)) == 0 { |
36 | 0 | return 2; |
37 | 0 | } |
38 | 0 | if (value & (0xffffffffffffffffu64 << 21)) == 0 { |
39 | 0 | return 3; |
40 | 0 | } |
41 | 0 | if (value & (0xffffffffffffffffu64 << 28)) == 0 { |
42 | 0 | return 4; |
43 | 0 | } |
44 | 0 | if (value & (0xffffffffffffffffu64 << 35)) == 0 { |
45 | 0 | return 5; |
46 | 0 | } |
47 | 0 | if (value & (0xffffffffffffffffu64 << 42)) == 0 { |
48 | 0 | return 6; |
49 | 0 | } |
50 | 0 | if (value & (0xffffffffffffffffu64 << 49)) == 0 { |
51 | 0 | return 7; |
52 | 0 | } |
53 | 0 | if (value & (0xffffffffffffffffu64 << 56)) == 0 { |
54 | 0 | return 8; |
55 | 0 | } |
56 | 0 | if (value & (0xffffffffffffffffu64 << 63)) == 0 { |
57 | 0 | return 9; |
58 | 0 | } |
59 | 0 | 10 |
60 | 0 | } |
61 | | |
62 | | /// Given `u32` value compute varint encoded length. |
63 | 0 | pub fn compute_raw_varint32_size(value: u32) -> u32 { |
64 | 0 | compute_raw_varint64_size(value as u64) |
65 | 0 | } |
66 | | |
67 | | /// Helper trait implemented by integer types which could be encoded as varint. |
68 | | pub trait ProtobufVarint { |
69 | | /// Size of self when encoded as varint. |
70 | | fn len_varint(&self) -> u32; |
71 | | } |
72 | | |
73 | | /// Helper trait implemented by integer types which could be encoded as zigzag varint. |
74 | | pub trait ProtobufVarintZigzag { |
75 | | /// Size of self when encoded as zigzag varint. |
76 | | fn len_varint_zigzag(&self) -> u32; |
77 | | } |
78 | | |
79 | | impl ProtobufVarint for u64 { |
80 | 0 | fn len_varint(&self) -> u32 { |
81 | 0 | compute_raw_varint64_size(*self) |
82 | 0 | } |
83 | | } |
84 | | |
85 | | impl ProtobufVarint for u32 { |
86 | 0 | fn len_varint(&self) -> u32 { |
87 | 0 | (*self as u64).len_varint() |
88 | 0 | } |
89 | | } |
90 | | |
91 | | impl ProtobufVarint for i64 { |
92 | 0 | fn len_varint(&self) -> u32 { |
93 | 0 | // same as length of u64 |
94 | 0 | (*self as u64).len_varint() |
95 | 0 | } |
96 | | } |
97 | | |
98 | | impl ProtobufVarintZigzag for i64 { |
99 | 0 | fn len_varint_zigzag(&self) -> u32 { |
100 | 0 | compute_raw_varint64_size(encode_zig_zag_64(*self)) |
101 | 0 | } |
102 | | } |
103 | | |
104 | | impl ProtobufVarint for i32 { |
105 | 0 | fn len_varint(&self) -> u32 { |
106 | 0 | // sign-extend and then compute |
107 | 0 | (*self as i64).len_varint() |
108 | 0 | } |
109 | | } |
110 | | |
111 | | impl ProtobufVarintZigzag for i32 { |
112 | 0 | fn len_varint_zigzag(&self) -> u32 { |
113 | 0 | compute_raw_varint32_size(encode_zig_zag_32(*self)) |
114 | 0 | } |
115 | | } |
116 | | |
117 | | impl ProtobufVarint for bool { |
118 | 0 | fn len_varint(&self) -> u32 { |
119 | 0 | 1 |
120 | 0 | } |
121 | | } |
122 | | |
123 | | /* Commented out due to https://github.com/mozilla/rust/issues/8075 |
124 | | impl<E:ProtobufEnum> ProtobufVarint for E { |
125 | | fn len_varint(&self) -> u32 { |
126 | | self.value().len_varint() |
127 | | } |
128 | | } |
129 | | */ |
130 | | |
131 | | /// Size of serialized repeated packed field, excluding length and tag. |
132 | 0 | pub fn vec_packed_varint_data_size<T: ProtobufVarint>(vec: &[T]) -> u32 { |
133 | 0 | vec.iter().map(|v| v.len_varint()).fold(0, |a, i| a + i) |
134 | 0 | } |
135 | | |
136 | | /// Size of serialized repeated packed field, excluding length and tag. |
137 | 0 | pub fn vec_packed_varint_zigzag_data_size<T: ProtobufVarintZigzag>(vec: &[T]) -> u32 { |
138 | 0 | vec.iter() |
139 | 0 | .map(|v| v.len_varint_zigzag()) |
140 | 0 | .fold(0, |a, i| a + i) |
141 | 0 | } |
142 | | |
143 | | /// Size of serialized repeated packed enum field, excluding length and tag. |
144 | 0 | pub fn vec_packed_enum_data_size<E: ProtobufEnum>(vec: &[E]) -> u32 { |
145 | 0 | vec.iter() |
146 | 0 | .map(|e| compute_raw_varint32_size(e.value() as u32)) |
147 | 0 | .fold(0, |a, i| a + i) |
148 | 0 | } |
149 | | |
150 | | /// Size of serialized data with length prefix and tag |
151 | 0 | pub fn vec_packed_varint_size<T: ProtobufVarint>(field_number: u32, vec: &[T]) -> u32 { |
152 | 0 | if vec.is_empty() { |
153 | 0 | 0 |
154 | | } else { |
155 | 0 | let data_size = vec_packed_varint_data_size(vec); |
156 | 0 | tag_size(field_number) + data_size.len_varint() + data_size |
157 | | } |
158 | 0 | } |
159 | | |
160 | | /// Size of serialized data with length prefix and tag |
161 | 0 | pub fn vec_packed_varint_zigzag_size<T: ProtobufVarintZigzag>(field_number: u32, vec: &[T]) -> u32 { |
162 | 0 | if vec.is_empty() { |
163 | 0 | 0 |
164 | | } else { |
165 | 0 | let data_size = vec_packed_varint_zigzag_data_size(vec); |
166 | 0 | tag_size(field_number) + data_size.len_varint() + data_size |
167 | | } |
168 | 0 | } |
169 | | |
170 | | /// Size of serialized data with length prefix and tag |
171 | 0 | pub fn vec_packed_enum_size<E: ProtobufEnum>(field_number: u32, vec: &[E]) -> u32 { |
172 | 0 | if vec.is_empty() { |
173 | 0 | 0 |
174 | | } else { |
175 | 0 | let data_size = vec_packed_enum_data_size(vec); |
176 | 0 | tag_size(field_number) + data_size.len_varint() + data_size |
177 | | } |
178 | 0 | } |
179 | | |
180 | | /// Compute tag size. Size of tag does not depend on wire type. |
181 | 0 | pub fn tag_size(field_number: u32) -> u32 { |
182 | 0 | wire_format::Tag::make(field_number, WireType::WireTypeFixed64) |
183 | 0 | .value() |
184 | 0 | .len_varint() |
185 | 0 | } |
186 | | |
187 | 0 | fn value_size_no_tag<T: ProtobufVarint>(value: T, wt: WireType) -> u32 { |
188 | 0 | match wt { |
189 | 0 | WireType::WireTypeFixed64 => 8, |
190 | 0 | WireType::WireTypeFixed32 => 4, |
191 | 0 | WireType::WireTypeVarint => value.len_varint(), |
192 | 0 | _ => panic!(), |
193 | | } |
194 | 0 | } Unexecuted instantiation: protobuf::rt::value_size_no_tag::<i32> Unexecuted instantiation: protobuf::rt::value_size_no_tag::<u32> Unexecuted instantiation: protobuf::rt::value_size_no_tag::<i64> Unexecuted instantiation: protobuf::rt::value_size_no_tag::<u64> |
195 | | |
196 | | /// Integer value size when encoded as specified wire type. |
197 | 0 | pub fn value_size<T: ProtobufVarint>(field_number: u32, value: T, wt: WireType) -> u32 { |
198 | 0 | tag_size(field_number) + value_size_no_tag(value, wt) |
199 | 0 | } Unexecuted instantiation: protobuf::rt::value_size::<i32> Unexecuted instantiation: protobuf::rt::value_size::<u32> Unexecuted instantiation: protobuf::rt::value_size::<i64> Unexecuted instantiation: protobuf::rt::value_size::<u64> |
200 | | |
201 | | /// Integer value size when encoded as specified wire type. |
202 | 0 | pub fn value_varint_zigzag_size_no_tag<T: ProtobufVarintZigzag>(value: T) -> u32 { |
203 | 0 | value.len_varint_zigzag() |
204 | 0 | } Unexecuted instantiation: protobuf::rt::value_varint_zigzag_size_no_tag::<i32> Unexecuted instantiation: protobuf::rt::value_varint_zigzag_size_no_tag::<i64> |
205 | | |
206 | | /// Length of value when encoding with zigzag encoding with tag |
207 | 0 | pub fn value_varint_zigzag_size<T: ProtobufVarintZigzag>(field_number: u32, value: T) -> u32 { |
208 | 0 | tag_size(field_number) + value_varint_zigzag_size_no_tag(value) |
209 | 0 | } |
210 | | |
211 | 0 | fn enum_size_no_tag<E: ProtobufEnum>(value: E) -> u32 { |
212 | 0 | value.value().len_varint() |
213 | 0 | } Unexecuted instantiation: protobuf::rt::enum_size_no_tag::<protobuf::descriptor::FieldOptions_CType> Unexecuted instantiation: protobuf::rt::enum_size_no_tag::<protobuf::descriptor::FieldOptions_JSType> Unexecuted instantiation: protobuf::rt::enum_size_no_tag::<protobuf::descriptor::FileOptions_OptimizeMode> Unexecuted instantiation: protobuf::rt::enum_size_no_tag::<protobuf::descriptor::FieldDescriptorProto_Type> Unexecuted instantiation: protobuf::rt::enum_size_no_tag::<protobuf::descriptor::FieldDescriptorProto_Label> Unexecuted instantiation: protobuf::rt::enum_size_no_tag::<protobuf::descriptor::MethodOptions_IdempotencyLevel> Unexecuted instantiation: protobuf::rt::enum_size_no_tag::<protobuf::well_known_types::type_pb::Field_Kind> Unexecuted instantiation: protobuf::rt::enum_size_no_tag::<protobuf::well_known_types::type_pb::Field_Cardinality> Unexecuted instantiation: protobuf::rt::enum_size_no_tag::<protobuf::well_known_types::type_pb::Syntax> Unexecuted instantiation: protobuf::rt::enum_size_no_tag::<protobuf::well_known_types::struct_pb::NullValue> |
214 | | |
215 | | /// Size of encoded enum field value. |
216 | 0 | pub fn enum_size<E: ProtobufEnum>(field_number: u32, value: E) -> u32 { |
217 | 0 | tag_size(field_number) + enum_size_no_tag(value) |
218 | 0 | } Unexecuted instantiation: protobuf::rt::enum_size::<protobuf::descriptor::FieldOptions_CType> Unexecuted instantiation: protobuf::rt::enum_size::<protobuf::descriptor::FieldOptions_JSType> Unexecuted instantiation: protobuf::rt::enum_size::<protobuf::descriptor::FileOptions_OptimizeMode> Unexecuted instantiation: protobuf::rt::enum_size::<protobuf::descriptor::FieldDescriptorProto_Type> Unexecuted instantiation: protobuf::rt::enum_size::<protobuf::descriptor::FieldDescriptorProto_Label> Unexecuted instantiation: protobuf::rt::enum_size::<protobuf::descriptor::MethodOptions_IdempotencyLevel> Unexecuted instantiation: protobuf::rt::enum_size::<protobuf::well_known_types::type_pb::Field_Kind> Unexecuted instantiation: protobuf::rt::enum_size::<protobuf::well_known_types::type_pb::Field_Cardinality> Unexecuted instantiation: protobuf::rt::enum_size::<protobuf::well_known_types::type_pb::Syntax> Unexecuted instantiation: protobuf::rt::enum_size::<protobuf::well_known_types::struct_pb::NullValue> |
219 | | |
220 | 0 | fn bytes_size_no_tag(bytes: &[u8]) -> u32 { |
221 | 0 | compute_raw_varint64_size(bytes.len() as u64) + bytes.len() as u32 |
222 | 0 | } |
223 | | |
224 | | /// Size of encoded bytes field. |
225 | 0 | pub fn bytes_size(field_number: u32, bytes: &[u8]) -> u32 { |
226 | 0 | tag_size(field_number) + bytes_size_no_tag(bytes) |
227 | 0 | } |
228 | | |
229 | 0 | fn string_size_no_tag(s: &str) -> u32 { |
230 | 0 | bytes_size_no_tag(s.as_bytes()) |
231 | 0 | } |
232 | | |
233 | | /// Size of encoded string field. |
234 | 0 | pub fn string_size(field_number: u32, s: &str) -> u32 { |
235 | 0 | tag_size(field_number) + string_size_no_tag(s) |
236 | 0 | } |
237 | | |
238 | | /// Size of encoded unknown fields size. |
239 | 0 | pub fn unknown_fields_size(unknown_fields: &UnknownFields) -> u32 { |
240 | 0 | let mut r = 0; |
241 | 0 | for (number, values) in unknown_fields { |
242 | 0 | r += (tag_size(number) + 4) * values.fixed32.len() as u32; |
243 | 0 | r += (tag_size(number) + 8) * values.fixed64.len() as u32; |
244 | 0 |
|
245 | 0 | r += tag_size(number) * values.varint.len() as u32; |
246 | 0 | for varint in &values.varint { |
247 | 0 | r += varint.len_varint(); |
248 | 0 | } |
249 | | |
250 | 0 | r += tag_size(number) * values.length_delimited.len() as u32; |
251 | 0 | for bytes in &values.length_delimited { |
252 | 0 | r += bytes_size_no_tag(&bytes); |
253 | 0 | } |
254 | | } |
255 | 0 | r |
256 | 0 | } |
257 | | |
258 | | /// Read repeated `int32` field into given vec. |
259 | 0 | pub fn read_repeated_int32_into( |
260 | 0 | wire_type: WireType, |
261 | 0 | is: &mut CodedInputStream, |
262 | 0 | target: &mut Vec<i32>, |
263 | 0 | ) -> ProtobufResult<()> { |
264 | 0 | match wire_type { |
265 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_int32_into(target), |
266 | | WireType::WireTypeVarint => { |
267 | 0 | target.push(is.read_int32()?); |
268 | 0 | Ok(()) |
269 | | } |
270 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
271 | | } |
272 | 0 | } |
273 | | |
274 | | /// Read repeated `int64` field into given vec. |
275 | 0 | pub fn read_repeated_int64_into( |
276 | 0 | wire_type: WireType, |
277 | 0 | is: &mut CodedInputStream, |
278 | 0 | target: &mut Vec<i64>, |
279 | 0 | ) -> ProtobufResult<()> { |
280 | 0 | match wire_type { |
281 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_int64_into(target), |
282 | | WireType::WireTypeVarint => { |
283 | 0 | target.push(is.read_int64()?); |
284 | 0 | Ok(()) |
285 | | } |
286 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
287 | | } |
288 | 0 | } |
289 | | |
290 | | /// Read repeated `uint32` field into given vec. |
291 | 0 | pub fn read_repeated_uint32_into( |
292 | 0 | wire_type: WireType, |
293 | 0 | is: &mut CodedInputStream, |
294 | 0 | target: &mut Vec<u32>, |
295 | 0 | ) -> ProtobufResult<()> { |
296 | 0 | match wire_type { |
297 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_uint32_into(target), |
298 | | WireType::WireTypeVarint => { |
299 | 0 | target.push(is.read_uint32()?); |
300 | 0 | Ok(()) |
301 | | } |
302 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
303 | | } |
304 | 0 | } |
305 | | |
306 | | /// Read repeated `uint64` field into given vec. |
307 | 0 | pub fn read_repeated_uint64_into( |
308 | 0 | wire_type: WireType, |
309 | 0 | is: &mut CodedInputStream, |
310 | 0 | target: &mut Vec<u64>, |
311 | 0 | ) -> ProtobufResult<()> { |
312 | 0 | match wire_type { |
313 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_uint64_into(target), |
314 | | WireType::WireTypeVarint => { |
315 | 0 | target.push(is.read_uint64()?); |
316 | 0 | Ok(()) |
317 | | } |
318 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
319 | | } |
320 | 0 | } |
321 | | |
322 | | /// Read repeated `sint32` field into given vec. |
323 | 0 | pub fn read_repeated_sint32_into( |
324 | 0 | wire_type: WireType, |
325 | 0 | is: &mut CodedInputStream, |
326 | 0 | target: &mut Vec<i32>, |
327 | 0 | ) -> ProtobufResult<()> { |
328 | 0 | match wire_type { |
329 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_sint32_into(target), |
330 | | WireType::WireTypeVarint => { |
331 | 0 | target.push(is.read_sint32()?); |
332 | 0 | Ok(()) |
333 | | } |
334 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
335 | | } |
336 | 0 | } |
337 | | |
338 | | /// Read repeated `sint64` field into given vec. |
339 | 0 | pub fn read_repeated_sint64_into( |
340 | 0 | wire_type: WireType, |
341 | 0 | is: &mut CodedInputStream, |
342 | 0 | target: &mut Vec<i64>, |
343 | 0 | ) -> ProtobufResult<()> { |
344 | 0 | match wire_type { |
345 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_sint64_into(target), |
346 | | WireType::WireTypeVarint => { |
347 | 0 | target.push(is.read_sint64()?); |
348 | 0 | Ok(()) |
349 | | } |
350 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
351 | | } |
352 | 0 | } |
353 | | |
354 | | /// Read repeated `fixed32` field into given vec. |
355 | 0 | pub fn read_repeated_fixed32_into( |
356 | 0 | wire_type: WireType, |
357 | 0 | is: &mut CodedInputStream, |
358 | 0 | target: &mut Vec<u32>, |
359 | 0 | ) -> ProtobufResult<()> { |
360 | 0 | match wire_type { |
361 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_fixed32_into(target), |
362 | | WireType::WireTypeFixed32 => { |
363 | 0 | target.push(is.read_fixed32()?); |
364 | 0 | Ok(()) |
365 | | } |
366 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
367 | | } |
368 | 0 | } |
369 | | |
370 | | /// Read repeated `fixed64` field into given vec. |
371 | 0 | pub fn read_repeated_fixed64_into( |
372 | 0 | wire_type: WireType, |
373 | 0 | is: &mut CodedInputStream, |
374 | 0 | target: &mut Vec<u64>, |
375 | 0 | ) -> ProtobufResult<()> { |
376 | 0 | match wire_type { |
377 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_fixed64_into(target), |
378 | | WireType::WireTypeFixed64 => { |
379 | 0 | target.push(is.read_fixed64()?); |
380 | 0 | Ok(()) |
381 | | } |
382 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
383 | | } |
384 | 0 | } |
385 | | |
386 | | /// Read repeated `sfixed32` field into given vec. |
387 | 0 | pub fn read_repeated_sfixed32_into( |
388 | 0 | wire_type: WireType, |
389 | 0 | is: &mut CodedInputStream, |
390 | 0 | target: &mut Vec<i32>, |
391 | 0 | ) -> ProtobufResult<()> { |
392 | 0 | match wire_type { |
393 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_sfixed32_into(target), |
394 | | WireType::WireTypeFixed32 => { |
395 | 0 | target.push(is.read_sfixed32()?); |
396 | 0 | Ok(()) |
397 | | } |
398 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
399 | | } |
400 | 0 | } |
401 | | |
402 | | /// Read repeated `sfixed64` field into given vec. |
403 | 0 | pub fn read_repeated_sfixed64_into( |
404 | 0 | wire_type: WireType, |
405 | 0 | is: &mut CodedInputStream, |
406 | 0 | target: &mut Vec<i64>, |
407 | 0 | ) -> ProtobufResult<()> { |
408 | 0 | match wire_type { |
409 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_sfixed64_into(target), |
410 | | WireType::WireTypeFixed64 => { |
411 | 0 | target.push(is.read_sfixed64()?); |
412 | 0 | Ok(()) |
413 | | } |
414 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
415 | | } |
416 | 0 | } |
417 | | |
418 | | /// Read repeated `double` field into given vec. |
419 | 0 | pub fn read_repeated_double_into( |
420 | 0 | wire_type: WireType, |
421 | 0 | is: &mut CodedInputStream, |
422 | 0 | target: &mut Vec<f64>, |
423 | 0 | ) -> ProtobufResult<()> { |
424 | 0 | match wire_type { |
425 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_double_into(target), |
426 | | WireType::WireTypeFixed64 => { |
427 | 0 | target.push(is.read_double()?); |
428 | 0 | Ok(()) |
429 | | } |
430 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
431 | | } |
432 | 0 | } |
433 | | |
434 | | /// Read repeated `float` field into given vec. |
435 | 0 | pub fn read_repeated_float_into( |
436 | 0 | wire_type: WireType, |
437 | 0 | is: &mut CodedInputStream, |
438 | 0 | target: &mut Vec<f32>, |
439 | 0 | ) -> ProtobufResult<()> { |
440 | 0 | match wire_type { |
441 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_float_into(target), |
442 | | WireType::WireTypeFixed32 => { |
443 | 0 | target.push(is.read_float()?); |
444 | 0 | Ok(()) |
445 | | } |
446 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
447 | | } |
448 | 0 | } |
449 | | |
450 | | /// Read repeated `bool` field into given vec. |
451 | 0 | pub fn read_repeated_bool_into( |
452 | 0 | wire_type: WireType, |
453 | 0 | is: &mut CodedInputStream, |
454 | 0 | target: &mut Vec<bool>, |
455 | 0 | ) -> ProtobufResult<()> { |
456 | 0 | match wire_type { |
457 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_bool_into(target), |
458 | | WireType::WireTypeVarint => { |
459 | 0 | target.push(is.read_bool()?); |
460 | 0 | Ok(()) |
461 | | } |
462 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
463 | | } |
464 | 0 | } |
465 | | |
466 | | /// Read repeated `enum` field into given vec. |
467 | | /// This function is no longer called from generated code, remove in 1.5. |
468 | 0 | pub fn read_repeated_enum_into<E: ProtobufEnum>( |
469 | 0 | wire_type: WireType, |
470 | 0 | is: &mut CodedInputStream, |
471 | 0 | target: &mut Vec<E>, |
472 | 0 | ) -> ProtobufResult<()> { |
473 | 0 | match wire_type { |
474 | 0 | WireType::WireTypeLengthDelimited => is.read_repeated_packed_enum_into(target), |
475 | | WireType::WireTypeVarint => { |
476 | 0 | target.push(is.read_enum()?); |
477 | 0 | Ok(()) |
478 | | } |
479 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
480 | | } |
481 | 0 | } |
482 | | |
483 | | /// Helper function to read single enum value. |
484 | | #[inline] |
485 | 0 | fn read_enum_with_unknown_fields_into<E: ProtobufEnum, C>( |
486 | 0 | is: &mut CodedInputStream, |
487 | 0 | target: C, |
488 | 0 | field_number: u32, |
489 | 0 | unknown_fields: &mut UnknownFields, |
490 | 0 | ) -> ProtobufResult<()> |
491 | 0 | where |
492 | 0 | C: FnOnce(E), |
493 | 0 | { |
494 | 0 | let i = is.read_int32()?; |
495 | 0 | match ProtobufEnum::from_i32(i) { |
496 | 0 | Some(e) => target(e), |
497 | 0 | None => unknown_fields.add_varint(field_number, i as i64 as u64), |
498 | | } |
499 | 0 | Ok(()) |
500 | 0 | } Unexecuted instantiation: protobuf::rt::read_enum_with_unknown_fields_into::<protobuf::descriptor::FieldOptions_CType, protobuf::rt::read_proto2_enum_with_unknown_fields_into<protobuf::descriptor::FieldOptions_CType>::{closure#0}> Unexecuted instantiation: protobuf::rt::read_enum_with_unknown_fields_into::<protobuf::descriptor::FieldOptions_JSType, protobuf::rt::read_proto2_enum_with_unknown_fields_into<protobuf::descriptor::FieldOptions_JSType>::{closure#0}> Unexecuted instantiation: protobuf::rt::read_enum_with_unknown_fields_into::<protobuf::descriptor::FileOptions_OptimizeMode, protobuf::rt::read_proto2_enum_with_unknown_fields_into<protobuf::descriptor::FileOptions_OptimizeMode>::{closure#0}> Unexecuted instantiation: protobuf::rt::read_enum_with_unknown_fields_into::<protobuf::descriptor::FieldDescriptorProto_Type, protobuf::rt::read_proto2_enum_with_unknown_fields_into<protobuf::descriptor::FieldDescriptorProto_Type>::{closure#0}> Unexecuted instantiation: protobuf::rt::read_enum_with_unknown_fields_into::<protobuf::descriptor::FieldDescriptorProto_Label, protobuf::rt::read_proto2_enum_with_unknown_fields_into<protobuf::descriptor::FieldDescriptorProto_Label>::{closure#0}> Unexecuted instantiation: protobuf::rt::read_enum_with_unknown_fields_into::<protobuf::descriptor::MethodOptions_IdempotencyLevel, protobuf::rt::read_proto2_enum_with_unknown_fields_into<protobuf::descriptor::MethodOptions_IdempotencyLevel>::{closure#0}> Unexecuted instantiation: protobuf::rt::read_enum_with_unknown_fields_into::<protobuf::well_known_types::type_pb::Field_Kind, protobuf::rt::read_proto3_enum_with_unknown_fields_into<protobuf::well_known_types::type_pb::Field_Kind>::{closure#0}> Unexecuted instantiation: protobuf::rt::read_enum_with_unknown_fields_into::<protobuf::well_known_types::type_pb::Field_Cardinality, protobuf::rt::read_proto3_enum_with_unknown_fields_into<protobuf::well_known_types::type_pb::Field_Cardinality>::{closure#0}> Unexecuted instantiation: protobuf::rt::read_enum_with_unknown_fields_into::<protobuf::well_known_types::type_pb::Syntax, protobuf::rt::read_proto3_enum_with_unknown_fields_into<protobuf::well_known_types::type_pb::Syntax>::{closure#0}> |
501 | | |
502 | 0 | fn read_repeated_packed_enum_with_unknown_fields_into<E: ProtobufEnum>( |
503 | 0 | is: &mut CodedInputStream, |
504 | 0 | target: &mut Vec<E>, |
505 | 0 | field_number: u32, |
506 | 0 | unknown_fields: &mut UnknownFields, |
507 | 0 | ) -> ProtobufResult<()> { |
508 | 0 | let len = is.read_raw_varint64()?; |
509 | 0 | let old_limit = is.push_limit(len)?; |
510 | 0 | while !is.eof()? { |
511 | 0 | read_enum_with_unknown_fields_into(is, |e| target.push(e), field_number, unknown_fields)?; |
512 | | } |
513 | 0 | is.pop_limit(old_limit); |
514 | 0 | Ok(()) |
515 | 0 | } |
516 | | |
517 | | /// Read repeated `enum` field into given vec, |
518 | | /// and when value is unknown store it in unknown fields |
519 | | /// which matches proto2 spec. |
520 | | /// |
521 | | /// See explanation |
522 | | /// [here](https://github.com/stepancheg/rust-protobuf/issues/233#issuecomment-375142710) |
523 | 0 | pub fn read_repeated_enum_with_unknown_fields_into<E: ProtobufEnum>( |
524 | 0 | wire_type: WireType, |
525 | 0 | is: &mut CodedInputStream, |
526 | 0 | target: &mut Vec<E>, |
527 | 0 | field_number: u32, |
528 | 0 | unknown_fields: &mut UnknownFields, |
529 | 0 | ) -> ProtobufResult<()> { |
530 | 0 | match wire_type { |
531 | 0 | WireType::WireTypeLengthDelimited => read_repeated_packed_enum_with_unknown_fields_into( |
532 | 0 | is, |
533 | 0 | target, |
534 | 0 | field_number, |
535 | 0 | unknown_fields, |
536 | 0 | ), |
537 | | WireType::WireTypeVarint => { |
538 | 0 | read_enum_with_unknown_fields_into(is, |e| target.push(e), field_number, unknown_fields) |
539 | | } |
540 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
541 | | } |
542 | 0 | } |
543 | | |
544 | | /// Read repeated `enum` field into given vec, |
545 | | /// and when value is unknown store it in unknown fields |
546 | | /// which matches proto2 spec. |
547 | | /// |
548 | | /// See explanation |
549 | | /// [here](https://github.com/stepancheg/rust-protobuf/issues/233#issuecomment-375142710) |
550 | 0 | pub fn read_proto3_enum_with_unknown_fields_into<E: ProtobufEnum>( |
551 | 0 | wire_type: WireType, |
552 | 0 | is: &mut CodedInputStream, |
553 | 0 | target: &mut E, |
554 | 0 | field_number: u32, |
555 | 0 | unknown_fields: &mut UnknownFields, |
556 | 0 | ) -> ProtobufResult<()> { |
557 | 0 | if wire_type != WireType::WireTypeVarint { |
558 | 0 | return Err(unexpected_wire_type(wire_type)); |
559 | 0 | } |
560 | 0 |
|
561 | 0 | read_enum_with_unknown_fields_into(is, |e| *target = e, field_number, unknown_fields) Unexecuted instantiation: protobuf::rt::read_proto3_enum_with_unknown_fields_into::<protobuf::well_known_types::type_pb::Field_Kind>::{closure#0} Unexecuted instantiation: protobuf::rt::read_proto3_enum_with_unknown_fields_into::<protobuf::well_known_types::type_pb::Field_Cardinality>::{closure#0} Unexecuted instantiation: protobuf::rt::read_proto3_enum_with_unknown_fields_into::<protobuf::well_known_types::type_pb::Syntax>::{closure#0} |
562 | 0 | } Unexecuted instantiation: protobuf::rt::read_proto3_enum_with_unknown_fields_into::<protobuf::well_known_types::type_pb::Field_Kind> Unexecuted instantiation: protobuf::rt::read_proto3_enum_with_unknown_fields_into::<protobuf::well_known_types::type_pb::Field_Cardinality> Unexecuted instantiation: protobuf::rt::read_proto3_enum_with_unknown_fields_into::<protobuf::well_known_types::type_pb::Syntax> |
563 | | |
564 | | /// Read repeated `enum` field into given vec, |
565 | | /// and when value is unknown store it in unknown fields |
566 | | /// which matches proto2 spec. |
567 | | /// |
568 | | /// See explanation |
569 | | /// [here](https://github.com/stepancheg/rust-protobuf/issues/233#issuecomment-375142710) |
570 | 0 | pub fn read_proto2_enum_with_unknown_fields_into<E: ProtobufEnum>( |
571 | 0 | wire_type: WireType, |
572 | 0 | is: &mut CodedInputStream, |
573 | 0 | target: &mut Option<E>, |
574 | 0 | field_number: u32, |
575 | 0 | unknown_fields: &mut UnknownFields, |
576 | 0 | ) -> ProtobufResult<()> { |
577 | 0 | if wire_type != WireType::WireTypeVarint { |
578 | 0 | return Err(unexpected_wire_type(wire_type)); |
579 | 0 | } |
580 | 0 |
|
581 | 0 | read_enum_with_unknown_fields_into(is, |e| *target = Some(e), field_number, unknown_fields) Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::FieldOptions_CType>::{closure#0} Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::FieldOptions_JSType>::{closure#0} Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::FileOptions_OptimizeMode>::{closure#0} Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::FieldDescriptorProto_Type>::{closure#0} Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::FieldDescriptorProto_Label>::{closure#0} Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::MethodOptions_IdempotencyLevel>::{closure#0} |
582 | 0 | } Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::FieldOptions_CType> Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::FieldOptions_JSType> Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::FileOptions_OptimizeMode> Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::FieldDescriptorProto_Type> Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::FieldDescriptorProto_Label> Unexecuted instantiation: protobuf::rt::read_proto2_enum_with_unknown_fields_into::<protobuf::descriptor::MethodOptions_IdempotencyLevel> |
583 | | |
584 | | /// Read repeated `string` field into given vec. |
585 | 0 | pub fn read_repeated_string_into( |
586 | 0 | wire_type: WireType, |
587 | 0 | is: &mut CodedInputStream, |
588 | 0 | target: &mut RepeatedField<String>, |
589 | 0 | ) -> ProtobufResult<()> { |
590 | 0 | match wire_type { |
591 | | WireType::WireTypeLengthDelimited => { |
592 | 0 | let tmp = target.push_default(); |
593 | 0 | is.read_string_into(tmp) |
594 | | } |
595 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
596 | | } |
597 | 0 | } |
598 | | |
599 | | /// Read repeated `Chars` field into given vec. |
600 | | #[cfg(feature = "bytes")] |
601 | | pub fn read_repeated_carllerche_string_into( |
602 | | wire_type: WireType, |
603 | | is: &mut CodedInputStream, |
604 | | target: &mut Vec<Chars>, |
605 | | ) -> ProtobufResult<()> { |
606 | | match wire_type { |
607 | | WireType::WireTypeLengthDelimited => { |
608 | | target.push(is.read_carllerche_chars()?); |
609 | | Ok(()) |
610 | | } |
611 | | _ => Err(unexpected_wire_type(wire_type)), |
612 | | } |
613 | | } |
614 | | |
615 | | /// Read singular `string` field. |
616 | 0 | pub fn read_singular_string_into( |
617 | 0 | wire_type: WireType, |
618 | 0 | is: &mut CodedInputStream, |
619 | 0 | target: &mut SingularField<String>, |
620 | 0 | ) -> ProtobufResult<()> { |
621 | 0 | match wire_type { |
622 | | WireType::WireTypeLengthDelimited => { |
623 | 0 | let tmp = target.set_default(); |
624 | 0 | is.read_string_into(tmp) |
625 | | } |
626 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
627 | | } |
628 | 0 | } |
629 | | |
630 | | /// Read singular `Chars` field. |
631 | | #[cfg(feature = "bytes")] |
632 | | pub fn read_singular_carllerche_string_into( |
633 | | wire_type: WireType, |
634 | | is: &mut CodedInputStream, |
635 | | target: &mut Option<Chars>, |
636 | | ) -> ProtobufResult<()> { |
637 | | match wire_type { |
638 | | WireType::WireTypeLengthDelimited => { |
639 | | *target = Some(is.read_carllerche_chars()?); |
640 | | Ok(()) |
641 | | } |
642 | | _ => Err(unexpected_wire_type(wire_type)), |
643 | | } |
644 | | } |
645 | | |
646 | | /// Read singular `string` field for proto3. |
647 | 0 | pub fn read_singular_proto3_string_into( |
648 | 0 | wire_type: WireType, |
649 | 0 | is: &mut CodedInputStream, |
650 | 0 | target: &mut String, |
651 | 0 | ) -> ProtobufResult<()> { |
652 | 0 | match wire_type { |
653 | 0 | WireType::WireTypeLengthDelimited => is.read_string_into(target), |
654 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
655 | | } |
656 | 0 | } |
657 | | |
658 | | /// Read singular `Chars` field for proto3. |
659 | | #[cfg(feature = "bytes")] |
660 | | pub fn read_singular_proto3_carllerche_string_into( |
661 | | wire_type: WireType, |
662 | | is: &mut CodedInputStream, |
663 | | target: &mut Chars, |
664 | | ) -> ProtobufResult<()> { |
665 | | match wire_type { |
666 | | WireType::WireTypeLengthDelimited => { |
667 | | *target = is.read_carllerche_chars()?; |
668 | | Ok(()) |
669 | | } |
670 | | _ => Err(unexpected_wire_type(wire_type)), |
671 | | } |
672 | | } |
673 | | |
674 | | /// Read repeated `bytes` field into given vec. |
675 | 0 | pub fn read_repeated_bytes_into( |
676 | 0 | wire_type: WireType, |
677 | 0 | is: &mut CodedInputStream, |
678 | 0 | target: &mut RepeatedField<Vec<u8>>, |
679 | 0 | ) -> ProtobufResult<()> { |
680 | 0 | match wire_type { |
681 | | WireType::WireTypeLengthDelimited => { |
682 | 0 | let tmp = target.push_default(); |
683 | 0 | is.read_bytes_into(tmp) |
684 | | } |
685 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
686 | | } |
687 | 0 | } |
688 | | |
689 | | /// Read repeated `Bytes` field into given vec. |
690 | | #[cfg(feature = "bytes")] |
691 | | pub fn read_repeated_carllerche_bytes_into( |
692 | | wire_type: WireType, |
693 | | is: &mut CodedInputStream, |
694 | | target: &mut Vec<Bytes>, |
695 | | ) -> ProtobufResult<()> { |
696 | | match wire_type { |
697 | | WireType::WireTypeLengthDelimited => { |
698 | | target.push(is.read_carllerche_bytes()?); |
699 | | Ok(()) |
700 | | } |
701 | | _ => Err(unexpected_wire_type(wire_type)), |
702 | | } |
703 | | } |
704 | | |
705 | | /// Read singular `bytes` field. |
706 | 0 | pub fn read_singular_bytes_into( |
707 | 0 | wire_type: WireType, |
708 | 0 | is: &mut CodedInputStream, |
709 | 0 | target: &mut SingularField<Vec<u8>>, |
710 | 0 | ) -> ProtobufResult<()> { |
711 | 0 | match wire_type { |
712 | | WireType::WireTypeLengthDelimited => { |
713 | 0 | let tmp = target.set_default(); |
714 | 0 | is.read_bytes_into(tmp) |
715 | | } |
716 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
717 | | } |
718 | 0 | } |
719 | | |
720 | | /// Read singular `Bytes` field. |
721 | | #[cfg(feature = "bytes")] |
722 | | pub fn read_singular_carllerche_bytes_into( |
723 | | wire_type: WireType, |
724 | | is: &mut CodedInputStream, |
725 | | target: &mut Option<Bytes>, |
726 | | ) -> ProtobufResult<()> { |
727 | | match wire_type { |
728 | | WireType::WireTypeLengthDelimited => { |
729 | | *target = Some(is.read_carllerche_bytes()?); |
730 | | Ok(()) |
731 | | } |
732 | | _ => Err(unexpected_wire_type(wire_type)), |
733 | | } |
734 | | } |
735 | | |
736 | | /// Read singular `bytes` field for proto3. |
737 | 0 | pub fn read_singular_proto3_bytes_into( |
738 | 0 | wire_type: WireType, |
739 | 0 | is: &mut CodedInputStream, |
740 | 0 | target: &mut Vec<u8>, |
741 | 0 | ) -> ProtobufResult<()> { |
742 | 0 | match wire_type { |
743 | 0 | WireType::WireTypeLengthDelimited => is.read_bytes_into(target), |
744 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
745 | | } |
746 | 0 | } |
747 | | |
748 | | /// Read singular `Bytes` field for proto3. |
749 | | #[cfg(feature = "bytes")] |
750 | | pub fn read_singular_proto3_carllerche_bytes_into( |
751 | | wire_type: WireType, |
752 | | is: &mut CodedInputStream, |
753 | | target: &mut Bytes, |
754 | | ) -> ProtobufResult<()> { |
755 | | match wire_type { |
756 | | WireType::WireTypeLengthDelimited => { |
757 | | *target = is.read_carllerche_bytes()?; |
758 | | Ok(()) |
759 | | } |
760 | | _ => Err(unexpected_wire_type(wire_type)), |
761 | | } |
762 | | } |
763 | | |
764 | | /// Read repeated `message` field. |
765 | 0 | pub fn read_repeated_message_into<M: Message + Default>( |
766 | 0 | wire_type: WireType, |
767 | 0 | is: &mut CodedInputStream, |
768 | 0 | target: &mut RepeatedField<M>, |
769 | 0 | ) -> ProtobufResult<()> { |
770 | 0 | match wire_type { |
771 | | WireType::WireTypeLengthDelimited => { |
772 | 0 | is.incr_recursion()?; |
773 | 0 | let tmp = target.push_default(); |
774 | 0 | let res = is.merge_message(tmp); |
775 | 0 | is.decr_recursion(); |
776 | 0 | res |
777 | | } |
778 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
779 | | } |
780 | 0 | } Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<pprof::protos::profile::Line> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<pprof::protos::profile::Label> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<pprof::protos::profile::Sample> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<pprof::protos::profile::Mapping> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<pprof::protos::profile::Function> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<pprof::protos::profile::Location> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<pprof::protos::profile::ValueType> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::DescriptorProto> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::EnumDescriptorProto> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::FileDescriptorProto> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::UninterpretedOption> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::FieldDescriptorProto> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::OneofDescriptorProto> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::MethodDescriptorProto> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::ServiceDescriptorProto> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::SourceCodeInfo_Location> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::EnumValueDescriptorProto> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::GeneratedCodeInfo_Annotation> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::UninterpretedOption_NamePart> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::DescriptorProto_ReservedRange> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::DescriptorProto_ExtensionRange> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::descriptor::EnumDescriptorProto_EnumReservedRange> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::plugin::CodeGeneratorResponse_File> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::well_known_types::api::Mixin> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::well_known_types::api::Method> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::well_known_types::type_pb::Field> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::well_known_types::type_pb::Option> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::well_known_types::type_pb::EnumValue> Unexecuted instantiation: protobuf::rt::read_repeated_message_into::<protobuf::well_known_types::struct_pb::Value> |
781 | | |
782 | | /// Read singular `message` field. |
783 | 0 | pub fn read_singular_message_into<M: Message + Default>( |
784 | 0 | wire_type: WireType, |
785 | 0 | is: &mut CodedInputStream, |
786 | 0 | target: &mut SingularPtrField<M>, |
787 | 0 | ) -> ProtobufResult<()> { |
788 | 0 | match wire_type { |
789 | | WireType::WireTypeLengthDelimited => { |
790 | 0 | is.incr_recursion()?; |
791 | 0 | let tmp = target.set_default(); |
792 | 0 | let res = is.merge_message(tmp); |
793 | 0 | is.decr_recursion(); |
794 | 0 | res |
795 | | } |
796 | 0 | _ => Err(unexpected_wire_type(wire_type)), |
797 | | } |
798 | 0 | } Unexecuted instantiation: protobuf::rt::read_singular_message_into::<pprof::protos::profile::ValueType> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::EnumOptions> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::FileOptions> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::FieldOptions> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::OneofOptions> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::MethodOptions> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::MessageOptions> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::ServiceOptions> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::SourceCodeInfo> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::EnumValueOptions> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::GeneratedCodeInfo> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::descriptor::ExtensionRangeOptions> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::plugin::Version> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::well_known_types::source_context::SourceContext> Unexecuted instantiation: protobuf::rt::read_singular_message_into::<protobuf::well_known_types::any::Any> |
799 | | |
800 | 0 | fn skip_group(is: &mut CodedInputStream) -> ProtobufResult<()> { |
801 | | loop { |
802 | 0 | let (_, wire_type) = is.read_tag_unpack()?; |
803 | 0 | if wire_type == wire_format::WireTypeEndGroup { |
804 | 0 | return Ok(()); |
805 | 0 | } |
806 | 0 | is.skip_field(wire_type)?; |
807 | | } |
808 | 0 | } |
809 | | |
810 | | /// Handle unknown field in generated code. |
811 | | /// Either store a value in unknown, or skip a group. |
812 | 0 | pub fn read_unknown_or_skip_group( |
813 | 0 | field_number: u32, |
814 | 0 | wire_type: WireType, |
815 | 0 | is: &mut CodedInputStream, |
816 | 0 | unknown_fields: &mut UnknownFields, |
817 | 0 | ) -> ProtobufResult<()> { |
818 | 0 | match wire_type { |
819 | 0 | wire_format::WireTypeStartGroup => skip_group(is), |
820 | | _ => { |
821 | 0 | let unknown = is.read_unknown(wire_type)?; |
822 | 0 | unknown_fields.add_value(field_number, unknown); |
823 | 0 | Ok(()) |
824 | | } |
825 | | } |
826 | 0 | } |
827 | | |
828 | | /// Create an error for unexpected wire type. |
829 | | /// |
830 | | /// Function is used in generated code, so error types can be changed, |
831 | | /// but this function remains unchanged. |
832 | 0 | pub fn unexpected_wire_type(wire_type: WireType) -> ProtobufError { |
833 | 0 | ProtobufError::WireError(WireError::UnexpectedWireType(wire_type)) |
834 | 0 | } |
835 | | |
836 | | /// Compute serialized size of `map` field and cache nested field sizes. |
837 | 0 | pub fn compute_map_size<K, V>(field_number: u32, map: &HashMap<K::Value, V::Value>) -> u32 |
838 | 0 | where |
839 | 0 | K: ProtobufType, |
840 | 0 | V: ProtobufType, |
841 | 0 | K::Value: Eq + Hash, |
842 | 0 | { |
843 | 0 | let mut sum = 0; |
844 | 0 | for (k, v) in map { |
845 | 0 | let key_tag_size = 1; |
846 | 0 | let value_tag_size = 1; |
847 | 0 |
|
848 | 0 | let key_len = K::compute_size_with_length_delimiter(k); |
849 | 0 | let value_len = V::compute_size_with_length_delimiter(v); |
850 | 0 |
|
851 | 0 | let entry_len = key_tag_size + key_len + value_tag_size + value_len; |
852 | 0 | sum += tag_size(field_number) + compute_raw_varint32_size(entry_len) + entry_len; |
853 | 0 | } |
854 | 0 | sum |
855 | 0 | } |
856 | | |
857 | | /// Write map, message sizes must be already known. |
858 | 0 | pub fn write_map_with_cached_sizes<K, V>( |
859 | 0 | field_number: u32, |
860 | 0 | map: &HashMap<K::Value, V::Value>, |
861 | 0 | os: &mut CodedOutputStream, |
862 | 0 | ) -> ProtobufResult<()> |
863 | 0 | where |
864 | 0 | K: ProtobufType, |
865 | 0 | V: ProtobufType, |
866 | 0 | K::Value: Eq + Hash, |
867 | 0 | { |
868 | 0 | for (k, v) in map { |
869 | 0 | let key_tag_size = 1; |
870 | 0 | let value_tag_size = 1; |
871 | 0 |
|
872 | 0 | let key_len = K::get_cached_size_with_length_delimiter(k); |
873 | 0 | let value_len = V::get_cached_size_with_length_delimiter(v); |
874 | 0 |
|
875 | 0 | let entry_len = key_tag_size + key_len + value_tag_size + value_len; |
876 | 0 |
|
877 | 0 | os.write_tag(field_number, WireType::WireTypeLengthDelimited)?; |
878 | 0 | os.write_raw_varint32(entry_len)?; |
879 | 0 | K::write_with_cached_size(1, k, os)?; |
880 | 0 | V::write_with_cached_size(2, v, os)?; |
881 | | } |
882 | 0 | Ok(()) |
883 | 0 | } |
884 | | |
885 | | /// Read `map` field. |
886 | 0 | pub fn read_map_into<K, V>( |
887 | 0 | wire_type: WireType, |
888 | 0 | is: &mut CodedInputStream, |
889 | 0 | target: &mut HashMap<K::Value, V::Value>, |
890 | 0 | ) -> ProtobufResult<()> |
891 | 0 | where |
892 | 0 | K: ProtobufType, |
893 | 0 | V: ProtobufType, |
894 | 0 | K::Value: Eq + Hash + Default, |
895 | 0 | V::Value: Default, |
896 | 0 | { |
897 | 0 | if wire_type != WireType::WireTypeLengthDelimited { |
898 | 0 | return Err(unexpected_wire_type(wire_type)); |
899 | 0 | } |
900 | 0 |
|
901 | 0 | let mut key = Default::default(); |
902 | 0 | let mut value = Default::default(); |
903 | | |
904 | 0 | let len = is.read_raw_varint32()?; |
905 | 0 | let old_limit = is.push_limit(len as u64)?; |
906 | 0 | while !is.eof()? { |
907 | 0 | let (field_number, wire_type) = is.read_tag_unpack()?; |
908 | 0 | match field_number { |
909 | | 1 => { |
910 | 0 | if wire_type != K::wire_type() { |
911 | 0 | return Err(unexpected_wire_type(wire_type)); |
912 | 0 | } |
913 | 0 | key = K::read(is)?; |
914 | | } |
915 | | 2 => { |
916 | 0 | if wire_type != V::wire_type() { |
917 | 0 | return Err(unexpected_wire_type(wire_type)); |
918 | 0 | } |
919 | 0 | value = V::read(is)?; |
920 | | } |
921 | 0 | _ => is.skip_field(wire_type)?, |
922 | | } |
923 | | } |
924 | 0 | is.pop_limit(old_limit); |
925 | 0 |
|
926 | 0 | target.insert(key, value); |
927 | 0 |
|
928 | 0 | Ok(()) |
929 | 0 | } |