File tree 4 files changed +40
-6
lines changed
4 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,7 @@ pub trait BytesEncode<'a> {
47
47
/// Encode the given item as bytes.
48
48
fn bytes_encode ( item : & ' a Self :: EItem ) -> Result < Self :: ReturnBytes , Self :: Error > ;
49
49
50
- /// Encode the given item as bytes and write it into the writer. Returns the amount of bytes
51
- /// that were written.
50
+ /// Encode the given item as bytes and write it into the writer.
52
51
///
53
52
/// When implementing this, also take a look at [`zero_copy`][BytesEncode::zero_copy]'s
54
53
/// documentation.
@@ -57,13 +56,12 @@ pub trait BytesEncode<'a> {
57
56
fn bytes_encode_into_writer < W : io:: Write > (
58
57
item : & ' a Self :: EItem ,
59
58
writer : & mut W ,
60
- ) -> Result < usize , BoxedError > {
59
+ ) -> Result < ( ) , BoxedError > {
61
60
let bytes = Self :: bytes_encode ( item) ?;
62
- let bytes = bytes. as_ref ( ) ;
63
61
64
- writer. write_all ( bytes) ?;
62
+ writer. write_all ( bytes. as_ref ( ) ) ?;
65
63
66
- Ok ( bytes . len ( ) )
64
+ Ok ( ( ) )
67
65
}
68
66
}
69
67
Original file line number Diff line number Diff line change 16
16
17
17
type Error = bincode:: Error ;
18
18
19
+ fn zero_copy ( _item : & Self :: EItem ) -> bool {
20
+ false
21
+ }
22
+
19
23
fn bytes_encode ( item : & Self :: EItem ) -> Result < Self :: ReturnBytes , Self :: Error > {
20
24
bincode:: serialize ( item)
21
25
}
26
+
27
+ fn bytes_encode_into_writer < W : std:: io:: Write > (
28
+ item : & ' a Self :: EItem ,
29
+ writer : & mut W ,
30
+ ) -> Result < ( ) , BoxedError > {
31
+ bincode:: serialize_into ( writer, item) ?;
32
+ Ok ( ( ) )
33
+ }
22
34
}
23
35
24
36
impl < ' a , T : ' a > BytesDecode < ' a > for SerdeBincode < T >
Original file line number Diff line number Diff line change 16
16
17
17
type Error = serde_json:: Error ;
18
18
19
+ fn zero_copy ( _item : & Self :: EItem ) -> bool {
20
+ false
21
+ }
22
+
19
23
fn bytes_encode ( item : & Self :: EItem ) -> Result < Self :: ReturnBytes , Self :: Error > {
20
24
serde_json:: to_vec ( item)
21
25
}
26
+
27
+ fn bytes_encode_into_writer < W : std:: io:: Write > (
28
+ item : & ' a Self :: EItem ,
29
+ writer : & mut W ,
30
+ ) -> Result < ( ) , BoxedError > {
31
+ serde_json:: to_writer ( writer, item) ?;
32
+ Ok ( ( ) )
33
+ }
22
34
}
23
35
24
36
impl < ' a , T : ' a > BytesDecode < ' a > for SerdeJson < T >
Original file line number Diff line number Diff line change 16
16
17
17
type Error = rmp_serde:: encode:: Error ;
18
18
19
+ fn zero_copy ( _item : & Self :: EItem ) -> bool {
20
+ false
21
+ }
22
+
19
23
fn bytes_encode ( item : & Self :: EItem ) -> Result < Self :: ReturnBytes , Self :: Error > {
20
24
rmp_serde:: to_vec ( item)
21
25
}
26
+
27
+ fn bytes_encode_into_writer < W : std:: io:: Write > (
28
+ item : & ' a Self :: EItem ,
29
+ writer : & mut W ,
30
+ ) -> Result < ( ) , BoxedError > {
31
+ rmp_serde:: encode:: write ( writer, item) ?;
32
+ Ok ( ( ) )
33
+ }
22
34
}
23
35
24
36
impl < ' a , T : ' a > BytesDecode < ' a > for SerdeRmp < T >
You can’t perform that action at this time.
0 commit comments