Skip to main content

thruster_core/
http.rs

1use bytes::BytesMut;
2use tokio_util::codec::{Encoder, Decoder};
3
4use crate::response::{self, Response};
5use crate::request::{self, Request};
6use std::io;
7
8pub struct Http;
9
10impl Decoder for Http {
11    type Item = Request;
12    type Error = io::Error;
13
14
15    fn decode(&mut self, buf: &mut BytesMut) -> io::Result<Option<Request>> {
16        request::decode(buf)
17    }
18}
19
20impl Encoder for Http {
21    type Item = Response;
22    type Error = io::Error;
23
24
25    fn encode(&mut self, msg: Response, buf: &mut BytesMut) -> io::Result<()> {
26        response::encode(&msg, buf);
27
28        Ok(())
29    }
30}