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

Method from_bytes

nodedb-columnar/src/format.rs:64–96  ·  view source on GitHub ↗

Parse a header from bytes. Returns None if magic/version is invalid.

(data: &[u8])

Source from the content-addressed store, hash-verified

62
63 /// Parse a header from bytes. Returns None if magic/version is invalid.
64 pub fn from_bytes(data: &[u8]) -> Result<Self, crate::error::ColumnarError> {
65 if data.len() < HEADER_SIZE {
66 return Err(crate::error::ColumnarError::TruncatedSegment {
67 expected: HEADER_SIZE,
68 got: data.len(),
69 });
70 }
71
72 let mut magic = [0u8; 4];
73 magic.copy_from_slice(&data[0..4]);
74 if magic != MAGIC {
75 return Err(crate::error::ColumnarError::InvalidMagic(magic));
76 }
77
78 let version_major = data[4];
79 let version_minor = data[5];
80
81 // Reject incompatible major version.
82 if version_major > VERSION_MAJOR {
83 return Err(crate::error::ColumnarError::IncompatibleVersion {
84 reader_major: VERSION_MAJOR,
85 segment_major: version_major,
86 segment_minor: version_minor,
87 });
88 }
89
90 Ok(Self {
91 magic,
92 version_major,
93 version_minor,
94 endianness: data[6],
95 })
96 }
97}
98
99/// On-disk representation of a Bloom filter, bundled with the parameters

Callers

nothing calls this directly

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected