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

Method encode

websockets/chat-tcp/src/codec.rs:71–80  ·  view source on GitHub ↗
(&mut self, msg: ChatResponse, dst: &mut BytesMut)

Source from the content-addressed store, hash-verified

69
70 fn encode(&mut self, msg: ChatResponse, dst: &mut BytesMut) -> Result<(), Self::Error> {
71 let msg = json::to_string(&msg)?;
72 let msg_ref: &[u8] = msg.as_ref();
73
74 let size = u16::try_from(msg_ref.len()).map_err(|_| {
75 io::Error::new(io::ErrorKind::InvalidData, "chat frame exceeds 65535 bytes")
76 })?;
77
78 dst.reserve(msg_ref.len() + 2);
79 dst.put_u16(size);
80 dst.put(msg_ref);
81
82 Ok(())
83 }

Callers 2

make_encryptedFunction · 0.80
encrypt_payloadsFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected