ANNA Suite  2020b
Multipurpose development suite for Telco applications
Public Member Functions | Protected Member Functions | List of all members
anna::diameter::codec::basetypes::AvpData Class Referenceabstract

#include <AvpData.hpp>

Inheritance diagram for anna::diameter::codec::basetypes::AvpData:
Inheritance graph
[legend]

Public Member Functions

 AvpData ()
 
virtual std::string getFormatName () const =0
 
virtual int getSize () const =0
 
void code (char *buffer, int &size) noexcept(false)
 
virtual std::string asPrintableString () noexcept(false)
 
std::string asDataBlockString () noexcept(false)
 
virtual std::string asString () noexcept(false)
 
std::string asHexString () noexcept(false)
 
virtual void decode (const char *buffer, const int size) noexcept(false)=0
 
void fromPrintableString (const char *printableString) noexcept(false)
 
void fromHexString (const std::string &hexString) noexcept(false)
 

Protected Member Functions

std::string assertPrintable (const char *buffer, const int size) const noexcept(false)
 

Detailed Description

Diameter avp abstract data container

All diameter types inherit from this class. Basic types with one level, derived ones with two levels. Three or more inheritance levels have no sense. Each level has own private members and updateBasic() will be implemented at derived types to keep coherence towards parent ones. This coherence implies to call updateBasic when private members are updated.

  Basic diameter types are:      OctetString, Integer32, Integer64, Unsigned32, Unsigned64, Float32, Float64
  Derived diameter types are:    Address, Time, UTF8String, DiameterIdentity, DiameterURI, IPFilterRule, QoSFilterRule (derived from OctetString)
                                 Enumerated (derived from Integer32)
  Printable derived types are:   UTF8String, DiameterIdentity, DiameterURI, IPFilterRule, QoSFilterRule
  User application could create new diameter types derived for any basic one, and reimplement the methods to adjust its behaviour.
*

There are setters/getters at any level, and a lot of helpers to decode/interpret the stored data. Then, this class could be used as container and/or helper tool. Parent setters won't modify child members and vice versa, but helpers syncronizes both levels through parent 'code()' and child 'decode()' methods.

Derived types with own members, must use protected or private inheritance, and export base class methods desired (using declaration). This mechanism guarantees private members coherence between different levels: a derived type instance couldn't directly manipulate base class own members.

Constructor & Destructor Documentation

◆ AvpData()

anna::diameter::codec::basetypes::AvpData::AvpData ( )
inline

Default constructor

118 {};
Here is the call graph for this function:

Member Function Documentation

◆ asDataBlockString()

std::string anna::diameter::codec::basetypes::AvpData::asDataBlockString ( )
inlinenoexcept

Gets DataBlock binary block and ascii representation

Returns
String with DataBlock representation
171  {
172  int size = getSize();
173  char buffer[size];
174  code(buffer, size);
175  anna::DataBlock db(buffer, size);
176  return(db.asString());
177  }
void code(char *buffer, int &size) noexcept(false)
Definition: AvpData.hpp:147
Definition: DataBlock.hpp:24
Here is the call graph for this function:

◆ asHexString()

std::string anna::diameter::codec::basetypes::AvpData::asHexString ( )
inlinenoexcept

Gets the hexadecimal string representation for avp data Used in diameter message 'hex-data' field

Returns
Hexadecimal string representation for avp data
196  {
197  int size = getSize();
198  char buffer[size];
199  code(buffer, size);
200  anna::DataBlock db(buffer, size);
201  return anna::functions::asHexString(db);
202  }
static std::string asHexString(const int number)
void code(char *buffer, int &size) noexcept(false)
Definition: AvpData.hpp:147
Definition: DataBlock.hpp:24
Here is the call graph for this function:

◆ asPrintableString()

virtual std::string anna::diameter::codec::basetypes::AvpData::asPrintableString ( )
inlinevirtualnoexcept

Gets the natural/smart string representation for avp data (format-dependent content) Used in diameter message 'data' field Default implementation launch exception when data is not printable

Returns
Natural/smart string representation for avp data

Reimplemented in anna::diameter::codec::basetypes::Address, anna::diameter::codec::basetypes::Time, anna::diameter::helpers::tme::codectypes::Unsigned16, anna::diameter::codec::basetypes::Float32, anna::diameter::codec::basetypes::Float64, anna::diameter::codec::basetypes::Integer32, anna::diameter::codec::basetypes::Integer64, anna::diameter::codec::basetypes::Unsigned32, and anna::diameter::codec::basetypes::Unsigned64.

159  {
160  int size = getSize();
161  char buffer[size];
162  code(buffer, size);
163  return (assertPrintable(buffer, size));
164  }
std::string assertPrintable(const char *buffer, const int size) const noexcept(false)
Definition: AvpData.hpp:96
void code(char *buffer, int &size) noexcept(false)
Definition: AvpData.hpp:147
Here is the call graph for this function:

◆ assertPrintable()

std::string anna::diameter::codec::basetypes::AvpData::assertPrintable ( const char *  buffer,
const int  size 
) const
inlineprotectednoexcept

Asserts printable nature for buffer provided and launch exception if not. Must be invoked from 'updateBasic() and decode()' at derived diameter types, when buffer should be printable

Parameters
bufferRaw avp data
sizeRaw avp data length
Returns
Printable string or <null> if not printable
96  {
97  std::string result;
98 
99  if(size == 0) return result;
100 
101  bool printable;
102  result = anna::functions::asAsciiString(buffer, size, printable);
103 
104  if(!printable) {
105  std::string ex = getFormatName();
106  ex += "::assertPrintable | Non-printable data provided";
108  }
109 
110  return result;
111  }
static std::string asAsciiString(const char *buffer, int size, bool &isFullyPrintable)
virtual std::string getFormatName() const =0
#define ANNA_FILE_LOCATION
Definition: defines.hpp:23
Definition: RuntimeException.hpp:23
Here is the call graph for this function:

◆ asString()

virtual std::string anna::diameter::codec::basetypes::AvpData::asString ( void  )
inlinevirtualnoexcept

◆ code()

void anna::diameter::codec::basetypes::AvpData::code ( char *  buffer,
int &  size 
)
inlinenoexcept

Encodes avp data part over buffer externally allocated

Parameters
bufferRaw data to be encoded
sizeSize of raw data to be encoded
147  {
148  codeBasic(buffer, size);
149  }

◆ decode()

virtual void anna::diameter::codec::basetypes::AvpData::decode ( const char *  buffer,
const int  size 
)
pure virtualnoexcept

◆ fromHexString()

void anna::diameter::codec::basetypes::AvpData::fromHexString ( const std::string &  hexString)
inlinenoexcept

Initializes members from hexadecimal string representation. I.e.: af1233fb01 (even number of digits).

Parameters
hexStringRaw avp data in hexadecimal string representation
240  {
241  anna::DataBlock db(true);
242  anna::functions::fromHexString(hexString, db);
243  decode(db.getData(), db.getSize());
244  }
static DataBlock & fromHexString(const std::string &hexString, DataBlock &target) noexcept(false)
virtual void decode(const char *buffer, const int size) noexcept(false)=0
Definition: DataBlock.hpp:24
Here is the call graph for this function:

◆ fromPrintableString()

void anna::diameter::codec::basetypes::AvpData::fromPrintableString ( const char *  printableString)
inlinenoexcept

Initializes members from natural/smart string representation

Parameters
printableStringavp data in natural/smart string representation (human-readable)
224  {
225  if(!printableString) {
226  std::string ex = getFormatName();
227  ex += "::fromPrintableString | Null printableString provided";
229  }
230 
231  /*std::string dummy =*/assertPrintable(printableString, strlen(printableString));
232  setPrintableString(printableString);
233  }
std::string assertPrintable(const char *buffer, const int size) const noexcept(false)
Definition: AvpData.hpp:96
virtual std::string getFormatName() const =0
#define ANNA_FILE_LOCATION
Definition: defines.hpp:23
Definition: RuntimeException.hpp:23
Here is the call graph for this function:

◆ getFormatName()

virtual std::string anna::diameter::codec::basetypes::AvpData::getFormatName ( ) const
pure virtual

◆ getSize()

virtual int anna::diameter::codec::basetypes::AvpData::getSize ( ) const
pure virtual

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