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

BER object to handle octet string. More...

#include <src/BER.h>

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

Public Member Functions

 OctetStringBER (const char *value)
 Creates an OctetStringBER object.
 
 OctetStringBER (const char *value, const uint32_t length)
 Creates an OctetStringBER object.
 
virtual ~OctetStringBER ()
 OctetStringBER destructor.
 
virtual void encode (Stream &stream)
 Encodes OctetStringBER to stream.
 
virtual void decode (Stream &stream, const uint8_t flag=Flag::None)
 Decodes OctetStringBER from stream.
 
virtual uint8_t * encode (uint8_t *buffer)
 Encodes OctetStringBER to memory buffer.
 
virtual uint8_t * decode (uint8_t *buffer)
 Decodes OctetStringBER from memory buffer.
 
const char * getValue () const
 Gets the OctetStringBER value.
 
void setValue (const char *value, const unsigned int length)
 Sets the OctetStringBER value.
 
const bool getBit (const unsigned int index) const
 Gets bit at a given index in the OctetStringBER value.
 
- 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.
 
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

 OctetStringBER (const uint8_t type=Type::OctetString)
 Creates an empty OctetStringBER object.
 
void allocate ()
 Allocates the char array.
 
- Protected Member Functions inherited from SNMP::BER
BERcreate (const Type &type)
 Creates a BER of given type.
 

Protected Attributes

char * _value
 
- Protected Attributes inherited from SNMP::BER
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 to handle octet string.

  • Type is TYPE_OCTETSTRING.
  • Length is variable.
  • Size is variable.

Example

Octet String Encoding
01 23 45 67 89 AB CD EF 04 08 01 23 45 67 89 AB CD EF

Definition at line 1288 of file BER.h.

Constructor & Destructor Documentation

◆ OctetStringBER() [1/3]

SNMP::OctetStringBER::OctetStringBER ( const char * value)
inline

Creates an OctetStringBER object.

Creates an OctetStringBER object from a pointer to a null-terminated array of char.

The constructor allocates a char array and copies the value parameter.

Parameters
valueOctetStringBER char pointer value.

Definition at line 1300 of file BER.h.

◆ OctetStringBER() [2/3]

SNMP::OctetStringBER::OctetStringBER ( const char * value,
const uint32_t length )

Creates an OctetStringBER object.

Creates an OctetStringBER object from a pointer to an array of char and the array length.

The constructor allocates a char array and copies the value parameter.

Parameters
valueOctetStringBER char pointer value.
lengthValue length.

◆ ~OctetStringBER()

virtual SNMP::OctetStringBER::~OctetStringBER ( )
inlinevirtual

OctetStringBER destructor.

Releases the char array.

Definition at line 1322 of file BER.h.

References _value.

◆ OctetStringBER() [3/3]

SNMP::OctetStringBER::OctetStringBER ( const uint8_t type = Type::OctetString)
inlineprotected

Creates an empty OctetStringBER object.

Parameters
typeOctetStringBER type.

Definition at line 1430 of file BER.h.

References _value.

Member Function Documentation

◆ allocate()

void SNMP::OctetStringBER::allocate ( )
inlineprotected

Allocates the char array.

Definition at line 1438 of file BER.h.

References SNMP::BER::_length, and _value.

Referenced by decode(), SNMP::IPAddressBER::IPAddressBER(), and setValue().

◆ decode() [1/2]

virtual void SNMP::OctetStringBER::decode ( Stream & stream,
const uint8_t flag = Flag::None )
inlinevirtual

Decodes OctetStringBER from stream.

Type and length are decoded by the inherited BER::decode() then OctetStringBER value is decoded.

Parameters
streamStream to read from.
flagDecoding flag.

Reimplemented from SNMP::BER.

Definition at line 1349 of file BER.h.

References SNMP::BER::_length, _value, allocate(), and SNMP::BER::decode().

◆ decode() [2/2]

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

Decodes OctetStringBER from memory buffer.

Type and length are decoded by the inherited BER::decode() then OctetStringBER value is decoded.

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

Reimplemented from SNMP::BER.

Definition at line 1379 of file BER.h.

References SNMP::BER::_length, SNMP::BER::decode(), and setValue().

◆ encode() [1/2]

virtual void SNMP::OctetStringBER::encode ( Stream & stream)
inlinevirtual

Encodes OctetStringBER to stream.

Type and length are encoded by the inherited BER::encode() then OctetStringBER value is encoded.

Parameters
streamStream to write to.

Reimplemented from SNMP::BER.

Definition at line 1335 of file BER.h.

References SNMP::BER::_length, _value, and SNMP::BER::encode().

◆ encode() [2/2]

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

Encodes OctetStringBER to memory buffer.

Type and length are encoded by the inherited BER::encode() then OctetStringBER value is encoded.

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

Reimplemented from SNMP::BER.

Definition at line 1364 of file BER.h.

References SNMP::BER::_length, _value, and SNMP::BER::encode().

◆ getBit()

const bool SNMP::OctetStringBER::getBit ( const unsigned int index) const
inline

Gets bit at a given index in the OctetStringBER value.

Parameters
indexIndex of the bit.
Returns
Bit as boolean.

Definition at line 1415 of file BER.h.

References _value.

◆ getValue()

const char * SNMP::OctetStringBER::getValue ( ) const
inline

Gets the OctetStringBER value.

Returns
OctetStringBER char array pointer value.

Definition at line 1391 of file BER.h.

References _value.

◆ setValue()

void SNMP::OctetStringBER::setValue ( const char * value,
const unsigned int length )
inline

Sets the OctetStringBER value.

Note
Length is updated.
Parameters
valueOctetStringBER char pointer value.
lengthValue length.

Definition at line 1403 of file BER.h.

References SNMP::BER::_length, _value, and allocate().

Referenced by decode().

Member Data Documentation

◆ _value

char* SNMP::OctetStringBER::_value
protected

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