pub struct VariableInt { /* private fields */ }Expand description
Variable length integer as defined by MQTT specification
Encodes values using 1-4 bytes:
- 0-127: 1 byte
- 128-16,383: 2 bytes
- 16,384-2,097,151: 3 bytes
- 2,097,152-268,435,455: 4 bytes
Implementations§
Source§impl VariableInt
impl VariableInt
Sourcepub fn new(value: u32) -> Result<Self>
pub fn new(value: u32) -> Result<Self>
Creates a new VariableInt from a u32 value
§Errors
Returns MqttError::ProtocolError if the value exceeds the maximum
Sourcepub fn new_unchecked(value: u32) -> Self
pub fn new_unchecked(value: u32) -> Self
Creates a new VariableInt from a u32 value without validation
§Safety
The caller must ensure that value <= VARIABLE_INT_MAX
Sourcepub fn encoded_size(&self) -> u32
pub fn encoded_size(&self) -> u32
Returns the number of bytes needed to encode this value
Trait Implementations§
Source§impl BeBytes for VariableInt
impl BeBytes for VariableInt
fn field_size() -> usize
fn to_be_bytes(&self) -> Vec<u8> ⓘ
Source§fn try_from_be_bytes(bytes: &[u8]) -> Result<(Self, usize), BeBytesError>
fn try_from_be_bytes(bytes: &[u8]) -> Result<(Self, usize), BeBytesError>
Try to parse a struct from big-endian bytes Read more
fn to_le_bytes(&self) -> Vec<u8> ⓘ
Source§fn try_from_le_bytes(bytes: &[u8]) -> Result<(Self, usize), BeBytesError>
fn try_from_le_bytes(bytes: &[u8]) -> Result<(Self, usize), BeBytesError>
Try to parse a struct from little-endian bytes Read more
Source§fn to_be_bytes_buf(&self) -> Bytes
fn to_be_bytes_buf(&self) -> Bytes
Convert to big-endian bytes as a Bytes buffer Read more
Source§fn to_le_bytes_buf(&self) -> Bytes
fn to_le_bytes_buf(&self) -> Bytes
Convert to little-endian bytes as a Bytes buffer Read more
Source§fn encode_be_to<B>(&self, buf: &mut B) -> Result<(), BeBytesError>where
B: BufMut,
fn encode_be_to<B>(&self, buf: &mut B) -> Result<(), BeBytesError>where
B: BufMut,
Encode directly to a buffer in big-endian format Read more
Source§fn encode_le_to<B>(&self, buf: &mut B) -> Result<(), BeBytesError>where
B: BufMut,
fn encode_le_to<B>(&self, buf: &mut B) -> Result<(), BeBytesError>where
B: BufMut,
Encode directly to a buffer in little-endian format Read more
Source§impl Clone for VariableInt
impl Clone for VariableInt
Source§fn clone(&self) -> VariableInt
fn clone(&self) -> VariableInt
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for VariableInt
impl Debug for VariableInt
Source§impl Display for VariableInt
impl Display for VariableInt
Source§impl From<VariableInt> for u32
impl From<VariableInt> for u32
Source§fn from(v: VariableInt) -> Self
fn from(v: VariableInt) -> Self
Converts to this type from the input type.
Source§impl Hash for VariableInt
impl Hash for VariableInt
Source§impl PartialEq for VariableInt
impl PartialEq for VariableInt
Source§impl TryFrom<u32> for VariableInt
impl TryFrom<u32> for VariableInt
Source§impl TryFrom<usize> for VariableInt
impl TryFrom<usize> for VariableInt
impl Copy for VariableInt
impl Eq for VariableInt
impl StructuralPartialEq for VariableInt
Auto Trait Implementations§
impl Freeze for VariableInt
impl RefUnwindSafe for VariableInt
impl Send for VariableInt
impl Sync for VariableInt
impl Unpin for VariableInt
impl UnwindSafe for VariableInt
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more