BCDBuffer

Struct BCDBuffer 

Source
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: u8

Implementations§

Source§

impl BCDBuffer

Source

pub fn new() -> Self

Create a new BCD buffer

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn len_in_bytes(&self) -> usize

Get the length of the BCD in bytes.

Trait Implementations§

Source§

impl AsRef<[u8]> for BCDBuffer

Source§

fn as_ref(&self) -> &[u8]

Returns the BCD bytes. Use this function to obtain the output of the BCD buffer.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.