MCPcopy Create free account
hub / github.com/base/base / encode

Method encode

crates/consensus/protocol/src/frame.rs:195–203  ·  view source on GitHub ↗

Encode the frame into a byte vector.

(&self)

Source from the content-addressed store, hash-verified

193
194 /// Encode the frame into a byte vector.
195 pub fn encode(&self) -> Vec<u8> {
196 let mut encoded = Vec::with_capacity(16 + 2 + 4 + self.data.len() + 1);
197 encoded.extend_from_slice(&self.id);
198 encoded.extend_from_slice(&self.number.to_be_bytes());
199 encoded.extend_from_slice(&(self.data.len() as u32).to_be_bytes());
200 encoded.extend_from_slice(&self.data);
201 encoded.push(self.is_last as u8);
202 encoded
203 }
204
205 /// Decode a frame from a byte vector.
206 pub fn decode(encoded: &[u8]) -> Result<(usize, Self), FrameDecodingError> {

Callers 9

test_data_too_shortFunction · 0.45
test_decode_manyFunction · 0.45
mint_bearerMethod · 0.45
build_enrMethod · 0.45
encode_framesFunction · 0.45

Calls 2

lenMethod · 0.45
pushMethod · 0.45

Tested by 6

test_data_too_shortFunction · 0.36
test_decode_manyFunction · 0.36