codecs/encoding/framing/
bytes.rs1use bytes::BytesMut;
2use serde::{Deserialize, Serialize};
3use tokio_util::codec::Encoder;
4
5use super::BoxedFramingError;
6
7#[derive(Debug, Clone, Deserialize, Serialize)]
9pub struct BytesEncoderConfig;
10
11impl BytesEncoderConfig {
12 pub const fn new() -> Self {
14 Self
15 }
16
17 pub fn build(&self) -> BytesEncoder {
19 BytesEncoder
20 }
21}
22
23#[derive(Debug, Clone)]
31pub struct BytesEncoder;
32
33impl Default for BytesEncoderConfig {
34 fn default() -> Self {
36 Self
37 }
38}
39
40impl Encoder<()> for BytesEncoder {
41 type Error = BoxedFramingError;
42
43 fn encode(&mut self, _: (), _: &mut BytesMut) -> Result<(), BoxedFramingError> {
44 Ok(())
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn encode() {
54 let mut codec = BytesEncoder;
55
56 let mut buffer = BytesMut::from("abc");
57 codec.encode((), &mut buffer).unwrap();
58
59 assert_eq!(b"abc", &buffer[..]);
60 }
61}