pub struct Integer(/* private fields */);
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§
source§impl 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 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§
source§impl Ord for Integer
impl Ord for Integer
source§impl PartialEq<Unsigned> for Integer
impl PartialEq<Unsigned> for Integer
source§impl PartialEq for Integer
impl PartialEq for Integer
source§impl PartialOrd for Integer
impl PartialOrd for Integer
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more