(&mut self, msg: ChatResponse, dst: &mut BytesMut)
| 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 | } |
no outgoing calls
no test coverage detected