@@ -4,32 +4,6 @@ use tokio_util::codec::{Decoder, Encoder, LinesCodec};
4
4
5
5
use crate :: api:: json:: message;
6
6
7
- /// Parse an incoming request as JSON into the corresponding message type
8
- ///
9
- /// # Parameters
10
- ///
11
- /// * `line`: input request line to parse as a message
12
- ///
13
- /// # Errors
14
- ///
15
- /// When the line cannot be parsed as JSON, the underlying error is returned from serde_json.
16
- fn parse_request ( line : & str ) -> serde_json:: Result < message:: HyperionMessage > {
17
- serde_json:: from_str ( line)
18
- }
19
-
20
- /// Encode an outgoing reply as JSON
21
- ///
22
- /// # Parameters
23
- ///
24
- /// * `reply`: reply to encode as JSON
25
- ///
26
- /// # Errors
27
- ///
28
- /// When the reply cannot be encoded as JSON, the underlying error is returned from serde_json.
29
- fn encode_reply ( reply : & message:: HyperionResponse ) -> serde_json:: Result < String > {
30
- serde_json:: to_string ( reply)
31
- }
32
-
33
7
#[ derive( Debug , Error ) ]
34
8
pub enum JsonCodecError {
35
9
#[ error( "i/o error: {0}" ) ]
@@ -62,7 +36,7 @@ impl Decoder for JsonCodec {
62
36
fn decode ( & mut self , src : & mut BytesMut ) -> Result < Option < Self :: Item > , Self :: Error > {
63
37
match self . lines . decode ( src) {
64
38
Ok ( lines_result) => Ok ( match lines_result {
65
- Some ( ref line) => Some ( parse_request ( line) ?) ,
39
+ Some ( ref line) => Some ( serde_json :: from_str ( line) ?) ,
66
40
None => None ,
67
41
} ) ,
68
42
Err ( error) => Err ( error. into ( ) ) ,
@@ -78,7 +52,7 @@ impl Encoder<message::HyperionResponse> for JsonCodec {
78
52
item : message:: HyperionResponse ,
79
53
dst : & mut BytesMut ,
80
54
) -> Result < ( ) , Self :: Error > {
81
- match encode_reply ( & item) {
55
+ match serde_json :: to_string ( & item) {
82
56
Ok ( encoded) => Ok ( self . lines . encode ( encoded, dst) ?) ,
83
57
Err ( encode_error) => Err ( encode_error. into ( ) ) ,
84
58
}
0 commit comments