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

BER object to handle float. More...

#include <src/BER.h>

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

Public Member Functions

 FloatBER (const float value, const unsigned int type=Type::Float)
 Creates a FloatBER object.
 
virtual void encode (Stream &stream)
 Encodes FloatBER to stream.
 
virtual void decode (Stream &stream, const uint8_t flag=Flag::None)
 Decodes FloatBER from stream.
 
virtual uint8_t * encode (uint8_t *buffer)
 Encodes FloatBER to memory buffer.
 
virtual uint8_t * decode (uint8_t *buffer)
 Decodes FloatBER from memory buffer.
 
const float getValue () const
 Gets the FloatBER value.
 
void setValue (const float value)
 Sets the FloatBER 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 Attributes

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

Static Protected Attributes

static constexpr uint8_t LENGTH = 4
 

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 Member Functions inherited from SNMP::BER
BERcreate (const Type &type)
 Creates a BER of given type.
 

Detailed Description

BER object to handle float.

IEEE 754 single precision 32-bit is used to represent float.

  • Type is TYPE_FLOAT.
  • Length is fixed, 4 bytes, short form encoding.
  • Size is fixed, 6 bytes.

Example

Float Encoding
0 48 04 00 00 00 00
+inf 48 04 7F 80 00 00
-inf 48 04 FF 80 00 00
NaN 48 04 FF FF FF FF
Note
FloatBER is never used alone but always embedded in an OpaqueBER as an OpaqueFloatBER.

Definition at line 2473 of file BER.h.

Constructor & Destructor Documentation

◆ FloatBER()

SNMP::FloatBER::FloatBER ( const float value,
const unsigned int type = Type::Float )
inline

Creates a FloatBER object.

Parameters
valueFloatBER float value.
typeFloatBER type.

Definition at line 2481 of file BER.h.

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

Member Function Documentation

◆ decode() [1/2]

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

Decodes FloatBER from stream.

The inherited BER::decodeNumeric<T>() template function decodes type, length and value.

Parameters
streamStream to read from.
flagDecoding flag.

Reimplemented from SNMP::BER.

Definition at line 2509 of file BER.h.

References _value, and SNMP::BER::decodeNumeric().

◆ decode() [2/2]

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

Decodes FloatBER from memory buffer.

The inherited BER::decodeNumeric<T>() template function decodes type, length and value.

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

Reimplemented from SNMP::BER.

Definition at line 2536 of file BER.h.

References _value, and SNMP::BER::decodeNumeric().

◆ encode() [1/2]

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

Encodes FloatBER to stream.

The inherited BER::encodeNumeric<T>() template function encodes type, length and value.

Parameters
streamStream to write to.

Reimplemented from SNMP::BER.

Definition at line 2496 of file BER.h.

References _value, and SNMP::BER::encodeNumeric().

◆ encode() [2/2]

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

Encodes FloatBER to memory buffer.

The inherited BER::encodeNumeric<T>() template function encodes type, length and value.

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

Reimplemented from SNMP::BER.

Definition at line 2522 of file BER.h.

References _value, and SNMP::BER::encodeNumeric().

◆ getValue()

const float SNMP::FloatBER::getValue ( ) const
inline

Gets the FloatBER value.

Returns
FloatBER float value.

Definition at line 2547 of file BER.h.

References _value.

◆ setValue()

void SNMP::FloatBER::setValue ( const float value)
inline

Sets the FloatBER value.

Parameters
valueFloatBER float value.

Definition at line 2556 of file BER.h.

References _value.

Referenced by FloatBER().

Member Data Documentation

◆ _value

float SNMP::FloatBER::_value
protected

FloatBER float value.

Definition at line 2564 of file BER.h.

Referenced by decode(), decode(), encode(), encode(), getValue(), and setValue().

◆ LENGTH

uint8_t SNMP::FloatBER::LENGTH = 4
staticconstexprprotected

Fixed length of the FloatBER.

Definition at line 2562 of file BER.h.

Referenced by FloatBER().


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