MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / to_bytes

Method to_bytes

nodedb-cluster/src/wire.rs:189–199  ·  view source on GitHub ↗

Serialize to bytes (transport-agnostic). Binary format (v2, all little-endian): version(2) + msg_type(2) + source(8) + target(8) + vshard(4) + payload_len(4) + payload

(&self)

Source from the content-addressed store, hash-verified

187 /// Binary format (v2, all little-endian):
188 /// version(2) + msg_type(2) + source(8) + target(8) + vshard(4) + payload_len(4) + payload
189 pub fn to_bytes(&self) -> Vec<u8> {
190 let mut buf = Vec::with_capacity(28 + self.payload.len());
191 buf.extend_from_slice(&self.version.to_le_bytes());
192 buf.extend_from_slice(&(self.msg_type as u16).to_le_bytes());
193 buf.extend_from_slice(&self.source_node.to_le_bytes());
194 buf.extend_from_slice(&self.target_node.to_le_bytes());
195 buf.extend_from_slice(&self.vshard_id.to_le_bytes());
196 buf.extend_from_slice(&(self.payload.len() as u32).to_le_bytes());
197 buf.extend_from_slice(&self.payload);
198 buf
199 }
200
201 /// Deserialize from bytes.
202 pub fn from_bytes(buf: &[u8]) -> Option<Self> {

Calls 1

lenMethod · 0.45