pub trait DecodeNumberInclusive: Sized {
// Required method
fn decode_usize_inclusive(
bytes: &[u8],
) -> Result<(Self, usize), DecodeError>;
}Expand description
Trait for decoding numbers in “inclusive” mode
Inclusive mode is used for self-referential sizes (e.g., header length that includes itself). It subtracts the encoding overhead from the decoded value to get the original.
§How it works
For each size tier, there’s an overhead that was added during encoding:
- u3: overhead = 16 bits (2 bytes: ‘u’ marker + ‘3’ size marker)
- u4: overhead = 24 bits (3 bytes: ‘u’ + ‘4’ + value)
- u5: overhead = 40 bits (5 bytes: ‘u’ + ‘5’ + value)
- etc.
The decoder reads the encoded value and subtracts the overhead:
ⓘ
// Encoded: [u][4][0x01, 0x18] → 280 // Subtract overhead: 280 - 24 = 256 ✓Required Methods§
Sourcefn decode_usize_inclusive(bytes: &[u8]) -> Result<(Self, usize), DecodeError>
fn decode_usize_inclusive(bytes: &[u8]) -> Result<(Self, usize), DecodeError>
Decode a number in inclusive mode (subtracts encoding overhead from value)
Returns the decoded value and the number of bytes consumed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".