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

Function unwrap_bytes_versioned

nodedb-cluster/src/wire_version/envelope.rs:98–120  ·  view source on GitHub ↗

Unwrap a versioned envelope and return the inner bytes. Bytes must begin with the reserved [`ENVELOPE_MARKER`] (`0xc1`). Missing marker, version 0, or `version > CURRENT` are all errors.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

96/// Bytes must begin with the reserved [`ENVELOPE_MARKER`] (`0xc1`).
97/// Missing marker, version 0, or `version > CURRENT` are all errors.
98pub fn unwrap_bytes_versioned(bytes: &[u8]) -> Result<&[u8], WireVersionError> {
99 match parse_envelope(bytes)? {
100 Some((version_raw, inner)) => {
101 if version_raw == 0 {
102 return Err(WireVersionError::DecodeFailure(
103 "v2 envelope with version 0 is invalid".to_string(),
104 ));
105 }
106 let peer_version = WireVersion(version_raw);
107 if peer_version > WireVersion::CURRENT {
108 return Err(WireVersionError::UnsupportedVersion {
109 peer_version,
110 supported_min: WireVersion::CURRENT,
111 supported_max: WireVersion::CURRENT,
112 });
113 }
114 Ok(inner)
115 }
116 None => Err(WireVersionError::DecodeFailure(
117 "missing envelope marker: raw v1 frames are not accepted".to_string(),
118 )),
119 }
120}
121
122// ── Envelope encoding / parsing helpers ────────────────────────────────────
123

Callers 2

versioned_decodeFunction · 0.85

Calls 3

WireVersionClass · 0.85
to_stringMethod · 0.80
parse_envelopeFunction · 0.70

Tested by

no test coverage detected