pub struct BCDBuffer {
pub bytes: [u8; 20],
pub i: u8,
}Expand description
Buffer for writing Binary-Coded Decimal (BCD)
Binary-Coded Decimal (BCD) is extensively used by X.213 NSAP addresses. It is always used for the Initial Domain Identifier (IDI), but is often used for the Domain Specific Part (DSP) as well.
This uses a fixed-length buffer of 20 bytes, because NSAP addresses are forbidden from exceeding 20 bytes, with an exception for URLs established in ITU-T Rec. X.519. Despite this one exception, no decimal encoding of an NSAP address exceeds 20 bytes.
Fields§
§bytes: [u8; 20]§i: u8Implementations§
Source§impl BCDBuffer
impl BCDBuffer
Sourcepub fn push_str(&mut self, s: &str)
pub fn push_str(&mut self, s: &str)
Push a string of ASCII digits to the BCD buffer.
Each character MUST return true from u8::is_ascii_digit.
Sourcepub fn push_ascii_bytes(&mut self, bytes: &[u8])
pub fn push_ascii_bytes(&mut self, bytes: &[u8])
Push a u8 slice of ASCII digits to the BCD buffer.
The entire slice MUST return true from u8::is_ascii_digit.
Sourcepub fn push_digit_u8(&mut self, b: u8)
pub fn push_digit_u8(&mut self, b: u8)
Push a single ASCII digit into the BCD buffer.
b MUST return true from u8::is_ascii_digit.
Sourcepub fn push_nybble(&mut self, n: u8)
pub fn push_nybble(&mut self, n: u8)
Push an arbitrary nybble into the BCD buffer
This does not check if the nybble is a binary-coded decimal.
This is particularly useful for pushing the padding nybble 0b1111
that is used to pad an odd number of digits to an integral number of
octets.
Sourcepub fn push_byte(&mut self, byte: u8)
pub fn push_byte(&mut self, byte: u8)
Push a full byte into the BCD buffer
If the last nybble prior to pushing is unset, it stays unset at 0.
In other words, if the buffer contains 012 and you use this function
to push 0x34, the BCD buffer will then contain 012034.
Sourcepub fn len_in_bytes(&self) -> usize
pub fn len_in_bytes(&self) -> usize
Get the length of the BCD in bytes.