Encode a wire type into a caller-owned buffer. Buffer-first design: the caller controls allocation. The `to_bytes()` convenience method allocates when needed, but hot paths can reuse buffers via `encode()` directly.
| 24 | /// convenience method allocates when needed, but hot paths can reuse |
| 25 | /// buffers via `encode()` directly. |
| 26 | pub trait WireEncode { |
| 27 | /// Write the encoded representation into `buf`. |
| 28 | fn encode(&self, buf: &mut BytesMut); |
| 29 | |
| 30 | /// Return the exact encoded size in bytes. |
| 31 | fn encoded_size(&self) -> usize; |
| 32 | |
| 33 | /// Convenience: allocate a new [`Bytes`] and encode into it. |
| 34 | #[must_use] |
| 35 | fn to_bytes(&self) -> Bytes { |
| 36 | let mut buf = BytesMut::with_capacity(self.encoded_size()); |
| 37 | self.encode(&mut buf); |
| 38 | buf.freeze() |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /// Decode a wire type from a byte slice. |
| 43 | /// |
no outgoing calls
no test coverage detected