SNMP 2.0.0
Loading...
Searching...
No Matches
SNMP::BER Class Reference

BER object. More...

#include <src/BER.h>

Inheritance diagram for SNMP::BER:
[legend]
Collaboration diagram for SNMP::BER:
[legend]

Public Member Functions

 BER (const unsigned int type)
 Creates a BER object.
 
virtual ~BER ()
 BER destructor.
 
virtual void encode (Stream &stream)
 Encodes BER type and length to stream.
 
template<typename T >
void encodeNumeric (T value, Stream &stream)
 Encodes BER numeric value to stream.
 
virtual void decode (Stream &stream, const uint8_t flag=Flag::None)
 Decodes BER type and length from stream.
 
template<typename T >
void decodeNumeric (T *value, Stream &stream, const uint8_t flag=Flag::None)
 Decodes BER numeric value from stream.
 
virtual uint8_t * encode (uint8_t *buffer)
 Encodes BER type and length to memory buffer.
 
template<typename T >
uint8_t * encodeNumeric (T value, uint8_t *buffer)
 Encodes BER numeric value to memory buffer.
 
virtual uint8_t * decode (uint8_t *buffer)
 Decodes BER type and length from memory buffer.
 
template<typename T >
uint8_t * decodeNumeric (T *value, uint8_t *buffer, const uint8_t flag=Flag::None)
 Decodes BER numeric value from memory buffer.
 
template<typename T >
void setNegative (T value)
 Computes BER length of a negative integer.
 
template<typename T >
void setPositive (T value)
 Computes BER length of a positive integer.
 
const unsigned int getType () const
 Gets the BER type.
 
const unsigned int getLength () const
 Gets the BER length.
 
virtual const unsigned int getSize (const bool refresh=false)
 Gets the size of the BER.
 
- Public Member Functions inherited from SNMP::Base
void encode7bits (uint32_t value, uint8_t *buffer, const uint8_t size)
 Encodes integer value to memory buffer.
 

Protected Member Functions

BERcreate (const Type &type)
 Creates a BER of given type.
 

Protected Attributes

Length _length
 
Type _type
 
- Protected Attributes inherited from SNMP::Base
unsigned int _size = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from SNMP::Base
static void encode7bits (uint32_t value, Stream &stream, const uint8_t size)
 Encodes integer value to stream.
 

Detailed Description

BER object.

This class is the base class of all the BER objects.

A BER object uses the TLV format. TLV is an acronym for type, length and value.

  • Type is the type of the object.
  • Length is the length of the value of the object.
  • Value is the value of the object.

Definition at line 792 of file BER.h.

Constructor & Destructor Documentation

◆ BER()

SNMP::BER::BER ( const unsigned int type)
inline

Creates a BER object.

Parameters
typeBER type.

Definition at line 799 of file BER.h.

References _length, and _type.

◆ ~BER()

virtual SNMP::BER::~BER ( )
inlinevirtual

BER destructor.

Definition at line 808 of file BER.h.

Member Function Documentation

◆ create()

BER * SNMP::BER::create ( const Type & type)
protected

Creates a BER of given type.

Parameters
typeBER type.
Returns
Pointer to created BER or nullptr if the type is unknown.

Referenced by SNMP::ArrayBER< U >::decode(), SNMP::ArrayBER< U >::decode(), SNMP::OpaqueBER::decode(), and SNMP::OpaqueBER::decode().

◆ decode() [1/2]

◆ decode() [2/2]

virtual uint8_t * SNMP::BER::decode ( uint8_t * buffer)
inlinevirtual

Decodes BER type and length from memory buffer.

Warning
Must be called first by derived class in overridden functions.
Parameters
bufferPointer to the buffer.
Returns
Next position to be read in buffer.

Reimplemented in SNMP::ArrayBER< U >, SNMP::ArrayBER< 2 >, SNMP::ArrayBER< SNMP_CAPACITY >, SNMP::BooleanBER, SNMP::FloatBER, SNMP::IntegerBER, SNMP::ObjectIdentifierBER, SNMP::OctetStringBER, SNMP::OpaqueBER, SNMP::UIntegerBER< T >, SNMP::UIntegerBER< uint32_t >, and SNMP::UIntegerBER< uint64_t >.

Definition at line 921 of file BER.h.

References _length, _type, SNMP::Length::decode(), and SNMP::Type::decode().

◆ decodeNumeric() [1/2]

template<typename T >
void SNMP::BER::decodeNumeric ( T * value,
Stream & stream,
const uint8_t flag = Flag::None )
inline

Decodes BER numeric value from stream.

SNMP numeric values are big-endian. Most significants bytes are read first.

Template Parameters
TC++ type of the numeric value.
Parameters
valueNumeric value to decode.
streamStream to read from.
flagDecoding flag.

Definition at line 867 of file BER.h.

References _length, and decode().

Referenced by SNMP::FloatBER::decode(), SNMP::FloatBER::decode(), SNMP::IntegerBER::decode(), SNMP::IntegerBER::decode(), SNMP::UIntegerBER< T >::decode(), and SNMP::UIntegerBER< T >::decode().

◆ decodeNumeric() [2/2]

template<typename T >
uint8_t * SNMP::BER::decodeNumeric ( T * value,
uint8_t * buffer,
const uint8_t flag = Flag::None )
inline

Decodes BER numeric value from memory buffer.

SNMP numeric values are big-endian. Most significants bytes are read first.

Template Parameters
TC++ type of the numeric value.
Parameters
valueNumeric value to decode.
bufferPointer to the buffer.
flagDecoding flag.
Returns
Next position to be read in buffer.

Definition at line 939 of file BER.h.

References _length, and decode().

◆ encode() [1/2]

◆ encode() [2/2]

virtual uint8_t * SNMP::BER::encode ( uint8_t * buffer)
inlinevirtual

Encodes BER type and length to memory buffer.

Warning
Must be called first by derived class in overridden functions.
Parameters
bufferPointer to the buffer.
Returns
Next position to be written in buffer.

Reimplemented in SNMP::ArrayBER< U >, SNMP::ArrayBER< 2 >, SNMP::ArrayBER< SNMP_CAPACITY >, SNMP::BooleanBER, SNMP::FloatBER, SNMP::IntegerBER, SNMP::ObjectIdentifierBER, SNMP::OctetStringBER, SNMP::OpaqueBER, SNMP::UIntegerBER< T >, SNMP::UIntegerBER< uint32_t >, and SNMP::UIntegerBER< uint64_t >.

Definition at line 888 of file BER.h.

References _length, _type, SNMP::Length::encode(), and SNMP::Type::encode().

◆ encodeNumeric() [1/2]

template<typename T >
void SNMP::BER::encodeNumeric ( T value,
Stream & stream )
inline

Encodes BER numeric value to stream.

SNMP numeric values are big-endian. Most significants bytes are written first.

Template Parameters
TC++ type of the integer.
Parameters
valueInteger value to encode.
streamStream to write to.

Definition at line 834 of file BER.h.

References _length, and encode().

Referenced by SNMP::FloatBER::encode(), SNMP::FloatBER::encode(), SNMP::IntegerBER::encode(), SNMP::IntegerBER::encode(), SNMP::UIntegerBER< T >::encode(), and SNMP::UIntegerBER< T >::encode().

◆ encodeNumeric() [2/2]

template<typename T >
uint8_t * SNMP::BER::encodeNumeric ( T value,
uint8_t * buffer )
inline

Encodes BER numeric value to memory buffer.

SNMP numeric values are big-endian. Most significants bytes are written first.

Template Parameters
TC++ type of the numeric value.
Parameters
valueNumeric value to encode.
bufferPointer to the buffer.
Returns
Next position to be written in buffer.

Definition at line 905 of file BER.h.

References _length, and encode().

◆ getLength()

const unsigned int SNMP::BER::getLength ( ) const
inline

Gets the BER length.

Returns
BER length.

Definition at line 1005 of file BER.h.

References _length.

◆ getSize()

virtual const unsigned int SNMP::BER::getSize ( const bool refresh = false)
inlinevirtual

Gets the size of the BER.

The size of the BER is computed from:

Parameters
refreshUnused.
Returns
BER size.

Reimplemented in SNMP::ArrayBER< U >, SNMP::ArrayBER< 2 >, SNMP::ArrayBER< SNMP_CAPACITY >, SNMP::Message, and SNMP::OpaqueBER.

Definition at line 1021 of file BER.h.

References _length, SNMP::Base::_size, and _type.

Referenced by SNMP::ArrayBER< U >::add(), SNMP::ArrayBER< U >::decode(), SNMP::OpaqueBER::decode(), SNMP::ArrayBER< U >::getSize(), and SNMP::OpaqueBER::getSize().

◆ getType()

const unsigned int SNMP::BER::getType ( ) const
inline

Gets the BER type.

Returns
BER type.

Definition at line 996 of file BER.h.

References _type.

Referenced by SNMP::Message::parse().

◆ setNegative()

template<typename T >
void SNMP::BER::setNegative ( T value)
inline

Computes BER length of a negative integer.

Template Parameters
TC++ type of the integer.
Parameters
valueInteger value.

Definition at line 962 of file BER.h.

References _length.

Referenced by SNMP::IntegerBER::setValue().

◆ setPositive()

template<typename T >
void SNMP::BER::setPositive ( T value)
inline

Computes BER length of a positive integer.

Template Parameters
TC++ type of the integer.
Parameters
valueInteger value.

Definition at line 980 of file BER.h.

References _length.

Referenced by SNMP::IntegerBER::setValue(), and SNMP::UIntegerBER< T >::setValue().

Member Data Documentation

◆ _length

◆ _type

Type SNMP::BER::_type
protected

BER type.

Definition at line 1030 of file BER.h.

Referenced by BER(), decode(), decode(), encode(), encode(), getSize(), and getType().


The documentation for this class was generated from the following file: