libbgp  0.6
A C++ BGP Library.
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
libbgp::Serializable Class Referenceabstract

The serializable base class. More...

#include <serializable.h>

Inheritance diagram for libbgp::Serializable:
Inheritance graph
[legend]
Collaboration diagram for libbgp::Serializable:
Collaboration graph
[legend]

Public Member Functions

 Serializable (BgpLogHandler *logger)
 Construct a new Serializable:: Serializable object. More...
 
 ~Serializable ()
 Destroy the Serializable:: Serializable object.
 
ssize_t print (uint8_t *to, size_t buf_sz) const
 Print the Serializable object as human readable string. More...
 
ssize_t print (size_t indent, uint8_t *to, size_t buf_sz) const
 Print the Serializable object as human readable string, with indentation. More...
 
virtual ssize_t parse (const uint8_t *from, size_t msg_sz)=0
 Deserialize the object from buffer. More...
 
virtual ssize_t write (uint8_t *to, size_t buf_sz) const =0
 Serialize the object and write to buffer. More...
 
virtual ssize_t length () const
 Get size in bytes required to serialize the object. More...
 
bool hasError () const
 Check if error information available. More...
 
uint8_t getErrorCode () const
 
uint8_t getErrorSubCode () const
 
const uint8_t * getError () const
 
size_t getErrorLength () const
 
void setLogger (BgpLogHandler *logger)
 Replace logger for this object. More...
 

Protected Member Functions

virtual ssize_t doPrint (size_t indent, uint8_t **to, size_t *buf_sz) const =0
 Print implementation. More...
 
void setError (uint8_t err, uint8_t suberr, const uint8_t *data, size_t data_len)
 Set the error information. More...
 
void forwardParseError (const Serializable &other)
 Forward error information from other Serializable object. More...
 

Static Protected Member Functions

static ssize_t _print (size_t indent, uint8_t **to, size_t *buf_left, const char *format,...)
 Print helper. More...
 

Protected Attributes

uint8_t err_code
 
uint8_t err_subcode
 
size_t err_len
 
uint8_t * err_data
 
BgpLogHandlerlogger
 

Detailed Description

The serializable base class.

Definition at line 26 of file serializable.h.

Constructor & Destructor Documentation

◆ Serializable()

libbgp::Serializable::Serializable ( BgpLogHandler logger)

Construct a new Serializable:: Serializable object.

Parameters
loggerLogger for serializer/deserializer errors.

Definition at line 23 of file serializable.cc.

Member Function Documentation

◆ _print()

ssize_t libbgp::Serializable::_print ( size_t  indent,
uint8_t **  to,
size_t *  buf_left,
const char *  format,
  ... 
)
staticprotected

◆ doPrint()

virtual ssize_t libbgp::Serializable::doPrint ( size_t  indent,
uint8_t **  to,
size_t *  buf_sz 
) const
protectedpure virtual

◆ forwardParseError()

void libbgp::Serializable::forwardParseError ( const Serializable other)
protected

Forward error information from other Serializable object.

Parameters
otherThe other Serializable object.

Definition at line 97 of file serializable.cc.

References setError().

◆ hasError()

bool libbgp::Serializable::hasError ( ) const

◆ length()

ssize_t libbgp::Serializable::length ( ) const
virtual

◆ parse()

virtual ssize_t libbgp::Serializable::parse ( const uint8_t *  from,
size_t  msg_sz 
)
pure virtual

◆ print() [1/2]

ssize_t libbgp::Serializable::print ( uint8_t *  to,
size_t  buf_sz 
) const

Print the Serializable object as human readable string.

Parameters
toThe pointer to the string buffer.
buf_szThe length of string buffer.
Returns
ssize_t Bytes written.
Return values
-1Failed to print.
>=0 Bytes written.
Examples:
deserialize-and-serialize.cc.

Definition at line 110 of file serializable.cc.

References doPrint().

Referenced by libbgp::BgpPacket::doPrint(), and libbgp::BgpLogHandler::log().

◆ print() [2/2]

ssize_t libbgp::Serializable::print ( size_t  indent,
uint8_t *  to,
size_t  buf_sz 
) const

Print the Serializable object as human readable string, with indentation.

Parameters
indentindent level.
toThe pointer to the string buffer.
buf_szThe length of string buffer.
Returns
ssize_t Bytes written.
Return values
-1Failed to print.
>=0 Bytes written.

Definition at line 125 of file serializable.cc.

References doPrint().

◆ setError()

void libbgp::Serializable::setError ( uint8_t  err,
uint8_t  suberr,
const uint8_t *  data,
size_t  data_len 
)
protected

Set the error information.

Set the error information. The information is used by BgpFsm to send NOTIFICATION message to the peer.

Parameters
errThe error code.
suberrThe error subcode.
dataThe error data buffer.
data_lenThe length of error data buffer.
Exceptions
err_existError already set.

Definition at line 61 of file serializable.cc.

References libbgp::BgpLogHandler::log().

Referenced by forwardParseError(), libbgp::BgpKeepaliveMessage::parse(), libbgp::BgpOpenMessage::parse(), libbgp::BgpNotificationMessage::parse(), libbgp::BgpPathAttrib::parse(), libbgp::BgpUpdateMessage::parse(), libbgp::BgpCapability::parseHeader(), and libbgp::BgpPathAttrib::parseHeader().

◆ setLogger()

void libbgp::Serializable::setLogger ( BgpLogHandler logger)

Replace logger for this object.

Parameters
loggerThe new logger.

Definition at line 187 of file serializable.cc.

Referenced by libbgp::BgpPathAttrib::clone().

◆ write()

virtual ssize_t libbgp::Serializable::write ( uint8_t *  to,
size_t  buf_sz 
) const
pure virtual

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