MCPcopy Create free account
hub / github.com/actix/examples / decode

Method decode

websockets/chat-tcp/src/codec.rs:50–65  ·  view source on GitHub ↗
(&mut self, src: &mut BytesMut)

Source from the content-addressed store, hash-verified

48
49 fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
50 let size = {
51 if src.len() < 2 {
52 return Ok(None);
53 }
54 BigEndian::read_u16(src.as_ref()) as usize
55 };
56
57 if src.len() >= size + 2 {
58 let _ = src.split_to(2);
59 let buf = src.split_to(size);
60 Ok(Some(json::from_slice::<ChatRequest>(&buf)?))
61 } else {
62 Ok(None)
63 }
64 }
65}
66
67impl Encoder<ChatResponse> for ChatCodec {
68 type Error = io::Error;

Callers 5

encrypt_payloadsFunction · 0.80
stdin_callbackFunction · 0.80
stdin_callbackFunction · 0.80
stdin_callbackFunction · 0.80
test_pb2.pyFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected