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

Method to_bytes

nodedb-wal/src/tombstone.rs:44–57  ·  view source on GitHub ↗

Serialize to bytes.

(&self)

Source from the content-addressed store, hash-verified

42
43 /// Serialize to bytes.
44 pub fn to_bytes(&self) -> Result<Vec<u8>> {
45 let name_bytes = self.collection.as_bytes();
46 if name_bytes.len() > MAX_COLLECTION_NAME_LEN {
47 return Err(WalError::PayloadTooLarge {
48 size: name_bytes.len(),
49 max: MAX_COLLECTION_NAME_LEN,
50 });
51 }
52 let mut buf = Vec::with_capacity(self.wire_size());
53 buf.extend_from_slice(&(name_bytes.len() as u32).to_le_bytes());
54 buf.extend_from_slice(name_bytes);
55 buf.extend_from_slice(&self.purge_lsn.to_le_bytes());
56 Ok(buf)
57 }
58
59 /// Deserialize from bytes. Fails on truncation, oversize name, or non-UTF8.
60 pub fn from_bytes(buf: &[u8]) -> Result<Self> {

Callers 4

roundtripFunction · 0.45
detects_truncationFunction · 0.45
detects_corrupt_name_lenFunction · 0.45
empty_name_okFunction · 0.45

Calls 3

as_bytesMethod · 0.45
lenMethod · 0.45
wire_sizeMethod · 0.45

Tested by 4

roundtripFunction · 0.36
detects_truncationFunction · 0.36
detects_corrupt_name_lenFunction · 0.36
empty_name_okFunction · 0.36