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])
| 96 | /// Bytes must begin with the reserved [`ENVELOPE_MARKER`] (`0xc1`). |
| 97 | /// Missing marker, version 0, or `version > CURRENT` are all errors. |
| 98 | pub 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 |
no test coverage detected