pub struct Integer(_);
Expand description
A BER encoded integer.
As integers are variable length in BER, this type is just a simple wrapper
atop the underlying Bytes
value containing the raw content. A value of
this type is a signed integer. If a value is defined as an unsigned
integer, i.e., as INTEGER (0..MAX)
, you should use the sibling type
Unsigned
instead.
In addition to these two generic types, the content decoders also provide
methods to parse integers into native integer types such as i8
. If the
range of such a type is obviously enough, you might want to consider
using these methods instead.
BER Encoding
In BER, an INTEGER is encoded as a primitive value with the content octets providing a variable-length, big-endian, two‘s complement byte sequence of that integer. Thus, the most-significant bit of the first octet serves as the sign bit.
Implementations
sourceimpl Integer
impl Integer
sourcepub fn take_from<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<Self, DecodeError<S::Error>>
pub fn take_from<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<Self, DecodeError<S::Error>>
Takes a single signed integer from the beginning of an encoded value.
This requires the next value in cons
to be a primitive value with
a correctly encoded signed integer.
sourcepub fn from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<Self, DecodeError<S::Error>>
pub fn from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<Self, DecodeError<S::Error>>
Constructs a signed integer from the content of a primitive value.
sourcepub fn i8_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i8, DecodeError<S::Error>>
pub fn i8_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i8, DecodeError<S::Error>>
Constructs an i8
from the content of a primitive value.
sourcepub fn i16_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i16, DecodeError<S::Error>>
pub fn i16_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i16, DecodeError<S::Error>>
Constructs an i16
from the content of a primitive value.
sourcepub fn i32_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i32, DecodeError<S::Error>>
pub fn i32_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i32, DecodeError<S::Error>>
Constructs an i32
from the content of a primitive value.
sourcepub fn i64_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i64, DecodeError<S::Error>>
pub fn i64_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i64, DecodeError<S::Error>>
Constructs an i64
from the content of a primitive value.
sourcepub fn i128_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i128, DecodeError<S::Error>>
pub fn i128_from_primitive<S: Source>(
prim: &mut Primitive<'_, S>
) -> Result<i128, DecodeError<S::Error>>
Constructs an i128
from the content of a primitive value.
sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Trades the integer into a bytes value with the raw content octets.
sourcepub fn as_slice(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
pub fn as_slice(&self) -> &[u8]ⓘNotable traits for &mut [u8]impl Write for &mut [u8]impl Read for &[u8]
Returns a bytes slice with the raw content.
sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns whether the integer is positive.
Also returns false
if the number is zero.
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns whether the integer is negative.
Also returns false
if the number is zero.
Trait Implementations
sourceimpl Ord for Integer
impl Ord for Integer
sourceimpl PartialOrd<Integer> for Integer
impl PartialOrd<Integer> for Integer
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<'a> PrimitiveContent for &'a Integer
impl<'a> PrimitiveContent for &'a Integer
sourcefn encoded_len(&self, _mode: Mode) -> usize
fn encoded_len(&self, _mode: Mode) -> usize
Returns the length of the encoded content of this type.
sourcefn write_encoded<W: Write>(
&self,
_mode: Mode,
target: &mut W
) -> Result<(), Error>
fn write_encoded<W: Write>(
&self,
_mode: Mode,
target: &mut W
) -> Result<(), Error>
Writes the encoded content to a writer.
sourcefn to_encoded_bytes(&self, mode: Mode) -> Bytes
fn to_encoded_bytes(&self, mode: Mode) -> Bytes
Encodes the value to bytes (useful when you need to sign a structure)
sourcefn encode(self) -> Primitive<Self>
fn encode(self) -> Primitive<Self>
Returns a value encoder for this content using the natural tag. Read more
sourcefn encode_as(self, tag: Tag) -> Primitive<Self>
fn encode_as(self, tag: Tag) -> Primitive<Self>
Returns a value encoder for this content using the given tag. Read more
sourcefn encode_ref(&self) -> Primitive<&Self>
fn encode_ref(&self) -> Primitive<&Self>
Returns a value encoder for a reference using the natural tag.
sourcefn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>
fn encode_ref_as(&self, tag: Tag) -> Primitive<&Self>
Returns a value encoder for a reference using the given tag.
impl Eq for Integer
Auto Trait Implementations
impl RefUnwindSafe for Integer
impl Send for Integer
impl Sync for Integer
impl Unpin for Integer
impl UnwindSafe for Integer
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more