@@ -42,7 +42,7 @@ pub struct Tag {
42
42
pub trait Value {
43
43
const WIRE_TYPE : WireType ;
44
44
45
- fn encoded_len ( & self ) -> u64 ;
45
+ fn proto_len ( & self ) -> u64 ;
46
46
47
47
fn encode < W : Write > ( & self , writer : & mut W ) -> io:: Result < ( ) > ;
48
48
@@ -72,21 +72,21 @@ impl<V: Value> Pair<V> {
72
72
Pair { field, value }
73
73
}
74
74
75
- pub fn encoded_len ( & self ) -> u64 {
76
- let tag = Tag :: new ( self . field , V :: WIRE_TYPE ) . encoded_len ( ) ;
75
+ pub fn proto_len ( & self ) -> u64 {
76
+ let tag = Tag :: new ( self . field , V :: WIRE_TYPE ) . proto_len ( ) ;
77
77
let len_prefix = if V :: WIRE_TYPE == WireType :: LengthDelimited {
78
- self . value . encoded_len ( )
78
+ self . value . proto_len ( )
79
79
} else {
80
80
0
81
81
} ;
82
- let value = self . value . encoded_len ( ) ;
82
+ let value = self . value . proto_len ( ) ;
83
83
tag + len_prefix + value
84
84
}
85
85
86
86
#[ inline]
87
- pub fn encoded_len_small ( & self ) -> u64 {
88
- if self . value . encoded_len ( ) != 0 {
89
- self . encoded_len ( )
87
+ pub fn proto_len_small ( & self ) -> u64 {
88
+ if self . value . proto_len ( ) != 0 {
89
+ self . proto_len ( )
90
90
} else {
91
91
0
92
92
}
@@ -95,15 +95,15 @@ impl<V: Value> Pair<V> {
95
95
pub fn encode ( & self , writer : & mut impl Write ) -> io:: Result < ( ) > {
96
96
Tag :: new ( self . field , V :: WIRE_TYPE ) . encode ( writer) ?;
97
97
if V :: WIRE_TYPE == WireType :: LengthDelimited {
98
- let len = self . value . encoded_len ( ) ;
98
+ let len = self . value . proto_len ( ) ;
99
99
Varint ( len) . encode ( writer) ?;
100
100
}
101
101
self . value . encode ( writer)
102
102
}
103
103
104
104
#[ inline]
105
105
pub fn encode_small ( & self , writer : & mut impl Write ) -> io:: Result < ( ) > {
106
- let len = self . value . encoded_len ( ) ;
106
+ let len = self . value . proto_len ( ) ;
107
107
if len == 0 {
108
108
return Ok ( ( ) ) ;
109
109
}
@@ -120,10 +120,6 @@ pub trait TagEncodable {
120
120
fn encode_with_tag < W : Write > ( & self , w : & mut W , field : u32 ) -> io:: Result < ( ) > ;
121
121
}
122
122
123
- pub trait Identifiable : Value {
124
- fn id ( & self ) -> u64 ;
125
- }
126
-
127
123
/// The smallest possible protobuf field number.
128
124
const MIN_FIELD : u32 = 1 ;
129
125
@@ -144,16 +140,17 @@ pub enum WireType {
144
140
impl Varint {
145
141
/// Returns the number of bytes it takes to encode a varint. This is
146
142
/// between 1 and 10 bytes, inclusive.
147
- pub const fn encoded_len ( & self ) -> u64 {
143
+ pub const fn proto_len ( & self ) -> u64 {
148
144
// https://github.com/google/protobuf/blob/3.3.x/src/google/protobuf/io/coded_stream.h#L1301-L1309
149
145
( ( ( ( self . 0 | 1 ) . leading_zeros ( ) ^ 63 ) * 9 + 73 ) / 64 ) as u64
150
146
}
151
147
}
148
+
152
149
impl Value for Varint {
153
150
const WIRE_TYPE : WireType = WireType :: Varint ;
154
151
155
- fn encoded_len ( & self ) -> u64 {
156
- self . encoded_len ( )
152
+ fn proto_len ( & self ) -> u64 {
153
+ self . proto_len ( )
157
154
}
158
155
159
156
/// Encodes a varint according to protobuf semantics.
@@ -216,8 +213,8 @@ impl Tag {
216
213
}
217
214
218
215
#[ inline]
219
- pub const fn encoded_len ( self ) -> u64 {
220
- self . into_varint ( ) . encoded_len ( )
216
+ pub const fn proto_len ( self ) -> u64 {
217
+ self . into_varint ( ) . proto_len ( )
221
218
}
222
219
223
220
#[ inline]
@@ -250,10 +247,10 @@ where
250
247
{
251
248
const WIRE_TYPE : WireType = WireType :: LengthDelimited ;
252
249
253
- fn encoded_len ( & self ) -> u64 {
250
+ fn proto_len ( & self ) -> u64 {
254
251
self . values
255
252
. iter ( )
256
- . map ( |x| Varint :: from ( x) . encoded_len ( ) )
253
+ . map ( |x| Varint :: from ( x) . proto_len ( ) )
257
254
. sum ( )
258
255
}
259
256
@@ -272,6 +269,6 @@ mod tests {
272
269
#[ test]
273
270
fn max_varint_len ( ) {
274
271
assert_eq ! ( MAX_VARINT_LEN , 10 ) ;
275
- assert_eq ! ( MAX_VARINT_LEN , Varint ( u64 :: MAX ) . encoded_len ( ) ) ;
272
+ assert_eq ! ( MAX_VARINT_LEN , Varint ( u64 :: MAX ) . proto_len ( ) ) ;
276
273
}
277
274
}
0 commit comments