@@ -51,7 +51,7 @@ pub trait Value {
51
51
where
52
52
Self : Sized ,
53
53
{
54
- Pair :: new ( field, self )
54
+ Pair { field, value : self }
55
55
}
56
56
}
57
57
@@ -61,17 +61,17 @@ pub trait Value {
61
61
#[ derive( Copy , Clone ) ]
62
62
pub struct Varint ( pub u64 ) ;
63
63
64
+ /// A tag and value pair.
65
+ ///
66
+ /// The wire type isn't stored; it's provided by the Value implementation,
67
+ /// which allows us to specialize code.
64
68
pub struct Pair < V : Value > {
65
69
field : u32 ,
66
70
value : V ,
67
71
}
68
72
69
73
impl < V : Value > Pair < V > {
70
- #[ inline]
71
- pub const fn new ( field : u32 , value : V ) -> Self {
72
- Pair { field, value }
73
- }
74
-
74
+ /// Calculate the size of pair, without using the zero-size optimization.
75
75
pub fn proto_len ( & self ) -> u64 {
76
76
let tag = Tag :: new ( self . field , V :: WIRE_TYPE ) . proto_len ( ) ;
77
77
let value = self . value . proto_len ( ) ;
@@ -83,6 +83,7 @@ impl<V: Value> Pair<V> {
83
83
tag + len_prefix + value
84
84
}
85
85
86
+ /// Calculate the size of pair, using the zero-size optimization.
86
87
#[ inline]
87
88
pub fn proto_len_small ( & self ) -> u64 {
88
89
if self . value . proto_len ( ) != 0 {
@@ -92,6 +93,7 @@ impl<V: Value> Pair<V> {
92
93
}
93
94
}
94
95
96
+ /// Encodes into protobuf, without using the zero-size optimization.
95
97
pub fn encode ( & self , writer : & mut impl Write ) -> io:: Result < ( ) > {
96
98
Tag :: new ( self . field , V :: WIRE_TYPE ) . encode ( writer) ?;
97
99
if V :: WIRE_TYPE == WireType :: LengthDelimited {
@@ -101,6 +103,7 @@ impl<V: Value> Pair<V> {
101
103
self . value . encode ( writer)
102
104
}
103
105
106
+ /// Encodes into protobuf, using the zero-size optimization.
104
107
#[ inline]
105
108
pub fn encode_small ( & self , writer : & mut impl Write ) -> io:: Result < ( ) > {
106
109
let len = self . value . proto_len ( ) ;
@@ -116,10 +119,6 @@ impl<V: Value> Pair<V> {
116
119
}
117
120
}
118
121
119
- pub trait TagEncodable {
120
- fn encode_with_tag < W : Write > ( & self , w : & mut W , field : u32 ) -> io:: Result < ( ) > ;
121
- }
122
-
123
122
/// The smallest possible protobuf field number.
124
123
const MIN_FIELD : u32 = 1 ;
125
124
0 commit comments