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

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