SNMP 2.0.0
Loading...
Searching...
No Matches
SNMP::ArrayBER< U > Class Template Reference

Base class for BER array of BERs. More...

#include <src/BER.h>

Inheritance diagram for SNMP::ArrayBER< U >:
[legend]
Collaboration diagram for SNMP::ArrayBER< U >:
[legend]

Public Member Functions

 ArrayBER (const uint8_t type)
 Creates an ArrayBER.
 
 ~ArrayBER ()
 ArrayBER destructor.
 
virtual void encode (Stream &stream)
 Encodes ArrayBER to stream.
 
virtual void decode (Stream &stream, const uint8_t flag=Flag::None)
 Decodes ArrayBER from stream.
 
virtual uint8_t * encode (uint8_t *buffer)
 Encodes ArrayBER to memory buffer.
 
virtual uint8_t * decode (uint8_t *buffer)
 Decodes ArrayBER from memory buffer.
 
virtual const unsigned int getSize (const bool refresh=false)
 Gets the size of the ArrayBER.
 
BERoperator[] (const unsigned int index)
 Array subscript operator.
 
const uint8_t count () const
 Gets the count of BERs in the array.
 
- Public Member Functions inherited from SNMP::BER
 BER (const unsigned int type)
 Creates a BER object.
 
virtual ~BER ()
 BER destructor.
 
template<typename T >
void encodeNumeric (T value, Stream &stream)
 Encodes BER numeric value to stream.
 
template<typename T >
void decodeNumeric (T *value, Stream &stream, const uint8_t flag=Flag::None)
 Decodes BER numeric value from stream.
 
template<typename T >
uint8_t * encodeNumeric (T value, uint8_t *buffer)
 Encodes BER numeric value to 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.
 
- 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

BERadd (BER *ber)
 Adds a BER to the array.
 
void remove ()
 Removes the last BER in the array.
 
- Protected Member Functions inherited from SNMP::BER
BERcreate (const Type &type)
 Creates a BER of given type.
 

Private Attributes

uint8_t _count = 0
 
std::vector< BER * > _bers
 
BER_bers [U]
 

Friends

class Message
 
class VarBind
 
class VarBindList
 

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.
 
- Protected Attributes inherited from SNMP::BER
Length _length
 
Type _type
 
- Protected Attributes inherited from SNMP::Base
unsigned int _size = 0
 

Detailed Description

template<const uint8_t U>
class SNMP::ArrayBER< U >

Base class for BER array of BERs.

BERs are stored in an array or a vector depending on the definition of SNMP_VECTORS.

Template Parameters
USize of the array. Used only if SNMP_VECTORS is set to 0 or undefined.

Definition at line 1715 of file BER.h.

Constructor & Destructor Documentation

◆ ArrayBER()

template<const uint8_t U>
SNMP::ArrayBER< U >::ArrayBER ( const uint8_t type)
inline

Creates an ArrayBER.

Parameters
typeArrayBER type.

Definition at line 1722 of file BER.h.

◆ ~ArrayBER()

template<const uint8_t U>
SNMP::ArrayBER< U >::~ArrayBER ( )
inline

ArrayBER destructor.

Delete all BERs of the array.

Definition at line 1731 of file BER.h.

References SNMP::ArrayBER< U >::_bers, and SNMP::ArrayBER< U >::_count.

Member Function Documentation

◆ add()

template<const uint8_t U>
BER * SNMP::ArrayBER< U >::add ( BER * ber)
inlineprotected

Adds a BER to the array.

The length of the array is updated.

Parameters
berBER to add.
Returns
BER given as parameter.

Definition at line 1899 of file BER.h.

References SNMP::ArrayBER< U >::_bers, SNMP::ArrayBER< U >::_count, SNMP::BER::_length, and SNMP::BER::getSize().

Referenced by SNMP::Message::add(), SNMP::Message::build(), SNMP::ArrayBER< U >::decode(), and SNMP::ArrayBER< U >::decode().

◆ count()

template<const uint8_t U>
const uint8_t SNMP::ArrayBER< U >::count ( ) const
inline

Gets the count of BERs in the array.

Returns
Count of BERs.

Definition at line 1886 of file BER.h.

References SNMP::ArrayBER< U >::_count.

◆ decode() [1/2]

template<const uint8_t U>
virtual void SNMP::ArrayBER< U >::decode ( Stream & stream,
const uint8_t flag = Flag::None )
inlinevirtual

Decodes ArrayBER from stream.

Type and length are decoded by the inherited BER::decode() then each BER of the array is decoded.

Decoding of BER from stream implies 3 steps.

  • Type of BER is read from stream.
  • BER object is created from read type.
  • BER is decoded from stream with flag set to Flag::Typed to skip type decoding already done.
Parameters
streamStream to read from.
flagDecoding flag.

Reimplemented from SNMP::BER.

Definition at line 1776 of file BER.h.

References SNMP::BER::_length, SNMP::ArrayBER< U >::add(), SNMP::BER::create(), SNMP::BER::decode(), SNMP::Type::decode(), SNMP::BER::getSize(), and SNMP::Flag::Typed.

◆ decode() [2/2]

template<const uint8_t U>
virtual uint8_t * SNMP::ArrayBER< U >::decode ( uint8_t * buffer)
inlinevirtual

Decodes ArrayBER from memory buffer.

Type and length are decoded by the inherited BER::decode() then each BER of the array is decoded.

Parameters
bufferPointer to the buffer.
Returns
Next position to be read in buffer.

Reimplemented from SNMP::BER.

Definition at line 1826 of file BER.h.

References SNMP::BER::_length, SNMP::ArrayBER< U >::add(), SNMP::BER::create(), SNMP::BER::decode(), and SNMP::Type::decode().

◆ encode() [1/2]

template<const uint8_t U>
virtual void SNMP::ArrayBER< U >::encode ( Stream & stream)
inlinevirtual

Encodes ArrayBER to stream.

Type and length are encoded by the inherited BER::encode() then each BER of the array is encoded.

Parameters
streamStream to write to.

Reimplemented from SNMP::BER.

Definition at line 1753 of file BER.h.

References SNMP::ArrayBER< U >::_bers, SNMP::ArrayBER< U >::_count, and SNMP::BER::encode().

◆ encode() [2/2]

template<const uint8_t U>
virtual uint8_t * SNMP::ArrayBER< U >::encode ( uint8_t * buffer)
inlinevirtual

Encodes ArrayBER to memory buffer.

Type and length are encoded by the inherited BER::encode() then each BER of the array is encoded.

Parameters
bufferPointer to the buffer.
Returns
Next position to be written in buffer.

Reimplemented from SNMP::BER.

Definition at line 1803 of file BER.h.

References SNMP::ArrayBER< U >::_bers, SNMP::ArrayBER< U >::_count, and SNMP::BER::encode().

◆ getSize()

template<const uint8_t U>
virtual const unsigned int SNMP::ArrayBER< U >::getSize ( const bool refresh = false)
inlinevirtual

Gets the size of the ArrayBER.

The size of the ArrayBER is computed from:

Length is the sum of the size of all the BERs in the array.

Parameters
refreshIf true, computes size, if false returns already computed size.
Returns
BER size.

Reimplemented from SNMP::BER.

Reimplemented in SNMP::Message.

Definition at line 1859 of file BER.h.

References SNMP::ArrayBER< U >::_bers, SNMP::ArrayBER< U >::_count, SNMP::BER::_length, and SNMP::BER::getSize().

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

◆ operator[]()

template<const uint8_t U>
BER * SNMP::ArrayBER< U >::operator[] ( const unsigned int index)
inline

Array subscript operator.

Gets the BER at a given index in the array.

Parameters
indexIndex of the BER.
Returns
BER.

Definition at line 1877 of file BER.h.

References SNMP::ArrayBER< U >::_bers.

◆ remove()

template<const uint8_t U>
void SNMP::ArrayBER< U >::remove ( )
inlineprotected

Removes the last BER in the array.

The length of the array is updated.

Definition at line 1918 of file BER.h.

References SNMP::ArrayBER< U >::_bers, SNMP::ArrayBER< U >::_count, and SNMP::BER::_length.

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

Friends And Related Symbol Documentation

◆ Message

template<const uint8_t U>
friend class Message
friend

Definition at line 1943 of file BER.h.

◆ VarBind

template<const uint8_t U>
friend class VarBind
friend

Definition at line 1944 of file BER.h.

◆ VarBindList

template<const uint8_t U>
friend class VarBindList
friend

Definition at line 1945 of file BER.h.

Member Data Documentation

◆ _bers [1/2]

◆ _bers [2/2]

template<const uint8_t U>
BER* SNMP::ArrayBER< U >::_bers[U]
private

Array of U BERs.

Definition at line 1940 of file BER.h.

◆ _count

template<const uint8_t U>
uint8_t SNMP::ArrayBER< U >::_count = 0
private

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