diff options
Diffstat (limited to 'src/rt.rs')
-rw-r--r-- | src/rt.rs | 108 |
1 files changed, 52 insertions, 56 deletions
@@ -10,6 +10,8 @@ use crate::chars::Chars; #[cfg(feature = "bytes")] use bytes::Bytes; +use crate::coded_input_stream::CodedInputStream; +use crate::coded_output_stream::CodedOutputStream; use crate::enums::ProtobufEnum; use crate::error::ProtobufError; use crate::error::ProtobufResult; @@ -18,19 +20,13 @@ use crate::message::*; use crate::repeated::RepeatedField; use crate::singular::SingularField; use crate::singular::SingularPtrField; -use crate::stream::wire_format; -use crate::stream::wire_format::WireType; -use crate::stream::wire_format::WireTypeFixed32; -use crate::stream::wire_format::WireTypeFixed64; -use crate::stream::wire_format::WireTypeLengthDelimited; -use crate::stream::wire_format::WireTypeVarint; -use crate::stream::CodedInputStream; -use crate::stream::CodedOutputStream; use crate::types::*; use crate::zigzag::*; pub use crate::lazy_v2::LazyV2; use crate::unknown::UnknownFields; +use crate::wire_format; +use crate::wire_format::WireType; /// Given `u64` value compute varint encoded length. pub fn compute_raw_varint64_size(value: u64) -> u32 { @@ -184,16 +180,16 @@ pub fn vec_packed_enum_size<E: ProtobufEnum>(field_number: u32, vec: &[E]) -> u3 /// Compute tag size. Size of tag does not depend on wire type. pub fn tag_size(field_number: u32) -> u32 { - wire_format::Tag::make(field_number, WireTypeFixed64) + wire_format::Tag::make(field_number, WireType::WireTypeFixed64) .value() .len_varint() } fn value_size_no_tag<T: ProtobufVarint>(value: T, wt: WireType) -> u32 { match wt { - WireTypeFixed64 => 8, - WireTypeFixed32 => 4, - WireTypeVarint => value.len_varint(), + WireType::WireTypeFixed64 => 8, + WireType::WireTypeFixed32 => 4, + WireType::WireTypeVarint => value.len_varint(), _ => panic!(), } } @@ -267,8 +263,8 @@ pub fn read_repeated_int32_into( target: &mut Vec<i32>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_int32_into(target), - WireTypeVarint => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_int32_into(target), + WireType::WireTypeVarint => { target.push(is.read_int32()?); Ok(()) } @@ -283,8 +279,8 @@ pub fn read_repeated_int64_into( target: &mut Vec<i64>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_int64_into(target), - WireTypeVarint => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_int64_into(target), + WireType::WireTypeVarint => { target.push(is.read_int64()?); Ok(()) } @@ -299,8 +295,8 @@ pub fn read_repeated_uint32_into( target: &mut Vec<u32>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_uint32_into(target), - WireTypeVarint => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_uint32_into(target), + WireType::WireTypeVarint => { target.push(is.read_uint32()?); Ok(()) } @@ -315,8 +311,8 @@ pub fn read_repeated_uint64_into( target: &mut Vec<u64>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_uint64_into(target), - WireTypeVarint => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_uint64_into(target), + WireType::WireTypeVarint => { target.push(is.read_uint64()?); Ok(()) } @@ -331,8 +327,8 @@ pub fn read_repeated_sint32_into( target: &mut Vec<i32>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_sint32_into(target), - WireTypeVarint => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_sint32_into(target), + WireType::WireTypeVarint => { target.push(is.read_sint32()?); Ok(()) } @@ -347,8 +343,8 @@ pub fn read_repeated_sint64_into( target: &mut Vec<i64>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_sint64_into(target), - WireTypeVarint => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_sint64_into(target), + WireType::WireTypeVarint => { target.push(is.read_sint64()?); Ok(()) } @@ -363,8 +359,8 @@ pub fn read_repeated_fixed32_into( target: &mut Vec<u32>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_fixed32_into(target), - WireTypeFixed32 => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_fixed32_into(target), + WireType::WireTypeFixed32 => { target.push(is.read_fixed32()?); Ok(()) } @@ -379,8 +375,8 @@ pub fn read_repeated_fixed64_into( target: &mut Vec<u64>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_fixed64_into(target), - WireTypeFixed64 => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_fixed64_into(target), + WireType::WireTypeFixed64 => { target.push(is.read_fixed64()?); Ok(()) } @@ -395,8 +391,8 @@ pub fn read_repeated_sfixed32_into( target: &mut Vec<i32>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_sfixed32_into(target), - WireTypeFixed32 => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_sfixed32_into(target), + WireType::WireTypeFixed32 => { target.push(is.read_sfixed32()?); Ok(()) } @@ -411,8 +407,8 @@ pub fn read_repeated_sfixed64_into( target: &mut Vec<i64>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_sfixed64_into(target), - WireTypeFixed64 => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_sfixed64_into(target), + WireType::WireTypeFixed64 => { target.push(is.read_sfixed64()?); Ok(()) } @@ -427,8 +423,8 @@ pub fn read_repeated_double_into( target: &mut Vec<f64>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_double_into(target), - WireTypeFixed64 => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_double_into(target), + WireType::WireTypeFixed64 => { target.push(is.read_double()?); Ok(()) } @@ -443,8 +439,8 @@ pub fn read_repeated_float_into( target: &mut Vec<f32>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_float_into(target), - WireTypeFixed32 => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_float_into(target), + WireType::WireTypeFixed32 => { target.push(is.read_float()?); Ok(()) } @@ -459,8 +455,8 @@ pub fn read_repeated_bool_into( target: &mut Vec<bool>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_bool_into(target), - WireTypeVarint => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_bool_into(target), + WireType::WireTypeVarint => { target.push(is.read_bool()?); Ok(()) } @@ -476,8 +472,8 @@ pub fn read_repeated_enum_into<E: ProtobufEnum>( target: &mut Vec<E>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_repeated_packed_enum_into(target), - WireTypeVarint => { + WireType::WireTypeLengthDelimited => is.read_repeated_packed_enum_into(target), + WireType::WireTypeVarint => { target.push(is.read_enum()?); Ok(()) } @@ -533,13 +529,13 @@ pub fn read_repeated_enum_with_unknown_fields_into<E: ProtobufEnum>( unknown_fields: &mut UnknownFields, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => read_repeated_packed_enum_with_unknown_fields_into( + WireType::WireTypeLengthDelimited => read_repeated_packed_enum_with_unknown_fields_into( is, target, field_number, unknown_fields, ), - WireTypeVarint => { + WireType::WireTypeVarint => { read_enum_with_unknown_fields_into(is, |e| target.push(e), field_number, unknown_fields) } _ => Err(unexpected_wire_type(wire_type)), @@ -593,7 +589,7 @@ pub fn read_repeated_string_into( target: &mut RepeatedField<String>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { let tmp = target.push_default(); is.read_string_into(tmp) } @@ -609,7 +605,7 @@ pub fn read_repeated_carllerche_string_into( target: &mut Vec<Chars>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { target.push(is.read_carllerche_chars()?); Ok(()) } @@ -624,7 +620,7 @@ pub fn read_singular_string_into( target: &mut SingularField<String>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { let tmp = target.set_default(); is.read_string_into(tmp) } @@ -640,7 +636,7 @@ pub fn read_singular_carllerche_string_into( target: &mut Option<Chars>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { *target = Some(is.read_carllerche_chars()?); Ok(()) } @@ -655,7 +651,7 @@ pub fn read_singular_proto3_string_into( target: &mut String, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_string_into(target), + WireType::WireTypeLengthDelimited => is.read_string_into(target), _ => Err(unexpected_wire_type(wire_type)), } } @@ -668,7 +664,7 @@ pub fn read_singular_proto3_carllerche_string_into( target: &mut Chars, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { *target = is.read_carllerche_chars()?; Ok(()) } @@ -683,7 +679,7 @@ pub fn read_repeated_bytes_into( target: &mut RepeatedField<Vec<u8>>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { let tmp = target.push_default(); is.read_bytes_into(tmp) } @@ -699,7 +695,7 @@ pub fn read_repeated_carllerche_bytes_into( target: &mut Vec<Bytes>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { target.push(is.read_carllerche_bytes()?); Ok(()) } @@ -714,7 +710,7 @@ pub fn read_singular_bytes_into( target: &mut SingularField<Vec<u8>>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { let tmp = target.set_default(); is.read_bytes_into(tmp) } @@ -730,7 +726,7 @@ pub fn read_singular_carllerche_bytes_into( target: &mut Option<Bytes>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { *target = Some(is.read_carllerche_bytes()?); Ok(()) } @@ -745,7 +741,7 @@ pub fn read_singular_proto3_bytes_into( target: &mut Vec<u8>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => is.read_bytes_into(target), + WireType::WireTypeLengthDelimited => is.read_bytes_into(target), _ => Err(unexpected_wire_type(wire_type)), } } @@ -758,7 +754,7 @@ pub fn read_singular_proto3_carllerche_bytes_into( target: &mut Bytes, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { *target = is.read_carllerche_bytes()?; Ok(()) } @@ -773,7 +769,7 @@ pub fn read_repeated_message_into<M: Message + Default>( target: &mut RepeatedField<M>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { is.incr_recursion()?; let tmp = target.push_default(); let res = is.merge_message(tmp); @@ -791,7 +787,7 @@ pub fn read_singular_message_into<M: Message + Default>( target: &mut SingularPtrField<M>, ) -> ProtobufResult<()> { match wire_type { - WireTypeLengthDelimited => { + WireType::WireTypeLengthDelimited => { is.incr_recursion()?; let tmp = target.set_default(); let res = is.merge_message(tmp); |