pub trait EncodeNumberInclusive {
// Required method
fn encode_usize_inclusive(&self) -> Vec<u8> ⓘ;
}Expand description
Trait for encoding numbers in “inclusive” mode
Inclusive mode is used for self-referential sizes (e.g., header length that includes itself). It adds the encoding overhead to the value before encoding, ensuring that when decoded and the size of the encoding itself is added back, you get the original value.
§How it works
For each size tier, there’s an overhead:
- 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 encoding adds this overhead to the value, so:
ⓘ
// Normal: 256 → [u][4][0x01, 0x00] (3 bytes) // Inclusive: 256 → 256 + 24 = 280 → [u][4][0x01, 0x18] (3 bytes) // When decoded: 280 - 24 = 256 ✓This ensures values like 256 can be encoded even when they cause size overflow, and self-referential sizes (like “this header is N bytes including this field”) work correctly.
Required Methods§
Sourcefn encode_usize_inclusive(&self) -> Vec<u8> ⓘ
fn encode_usize_inclusive(&self) -> Vec<u8> ⓘ
Encode this number in inclusive mode (adds encoding overhead to value)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".