Kea 2.7.5
isc::dns::rdata::Rdata Class Referenceabstract

The Rdata class is an abstract base class that provides a set of common interfaces to manipulate concrete RDATA objects. More...

#include <rdata.h>

+ Inheritance diagram for isc::dns::rdata::Rdata:

Public Member Functions

Converter methods
virtual std::string toText () const =0
 Convert an Rdata to a string.
 
virtual void toWire (isc::util::OutputBuffer &buff) const =0
 Render the Rdata in the wire format into a buffer.
 
virtual void toWire (AbstractMessageRenderer &renderer) const =0
 Render the Rdata in the wire format into a MessageRenderer object.
 
Comparison method
virtual int compare (const Rdata &other) const =0
 Compare two instances of Rdata.
 
virtual uint16_t getLength () const
 Get the wire format length of an Rdata.
 

Constructors and Destructor

Note: The copy constructor and the assignment operator are intentionally defined as private.

Concrete classes should generally specialize their own versions of these methods.

 Rdata ()
 The default constructor.
 
virtual ~Rdata ()
 The destructor.
 

Detailed Description

The Rdata class is an abstract base class that provides a set of common interfaces to manipulate concrete RDATA objects.

Generally, a separate derived class directly inherited from the base Rdata class is defined for each well known RDATA. Each of such classes will define the common logic based on the corresponding protocol standard.

Since some types of RRs are class specific and the corresponding RDATA may have different semantics (e.g. type A for class IN and type A for class CH have different representations and semantics), we separate Rdata derived classes for such RR types in different namespaces. The namespace of types specific to a class is named the lower-cased class name; for example, RDATA of class IN-specific types are defined in the in namespace, and RDATA of class CH-specific types are defined in the ch namespace, and so on. The derived classes are named using the RR type name (upper cased) such as A or AAAA. Thus RDATA of type A RR for class IN and CH are defined as in::A and ch::A, respectively. Many other RR types are class independent; the derived Rdata classes for such RR types are defined in the generic namespace. Examples are generic::NS and generic::SOA.

If applications need to refer to these derived classes, it is generally recommended to prepend at least some part of the namespace because the same class name can be used in different namespaces. So, instead of doing

it is advisable to prepend at least in from the namespace:

using namespace isc::dns::rdata;
in::A& rdata_type_a;

In many cases, however, an application doesn't have to care about such derived classes. For instance, to parse an incoming DNS message an application wouldn't have to perform type specific operation unless the application is specifically concerned about a particular type. So, this API generally handles Rdata in a polymorphic way through a pointer or reference to this base abstract class.

Definition at line 120 of file rdata.h.

Constructor & Destructor Documentation

◆ Rdata()

isc::dns::rdata::Rdata::Rdata ( )
inlineprotected

The default constructor.

This is intentionally defined as protected as this base class should never be instantiated (except as part of a derived class). In many cases, the derived class wouldn't define a public default constructor either, because an Rdata object without concrete data isn't meaningful.

Definition at line 136 of file rdata.h.

◆ ~Rdata()

virtual isc::dns::rdata::Rdata::~Rdata ( )
inlinevirtual

The destructor.

Definition at line 142 of file rdata.h.

Member Function Documentation

◆ compare()

virtual int isc::dns::rdata::Rdata::compare ( const Rdata & other) const
pure virtual

Compare two instances of Rdata.

This method compares this and the other Rdata objects in terms of the DNSSEC sorting order as defined in RFC4034, and returns the result as an integer.

This is a pure virtual method without the definition; the actual comparison logic is specific to each derived concrete class and should be explicitly defined in the derived class.

Specific implementations of this method must confirm that this and the other are objects of the same concrete derived class of Rdata. This is normally done by dynamic_cast in the implementation. It also means if the assumption isn't met an exception of class std::bad_cast will be thrown.

Here is an implementation choice: instead of relying on dynamic_cast, we could first convert the data into wire-format and compare the pair as opaque data. This would be more polymorphic, but might involve significant overhead, especially for a large size of RDATA.

Parameters
otherthe right-hand operand to compare against.
Returns
< 0 if this would be sorted before other.
0 if this is identical to other in terms of sorting order.
> 0 if this would be sorted after other.

Implemented in isc::dns::rdata::generic::Generic, isc::dns::rdata::any::TSIG, isc::dns::rdata::ch::A, isc::dns::rdata::generic::NS, isc::dns::rdata::generic::OPT, isc::dns::rdata::generic::PTR, isc::dns::rdata::generic::RRSIG, isc::dns::rdata::generic::SOA, isc::dns::rdata::generic::TKEY, isc::dns::rdata::generic::TXT, isc::dns::rdata::in::A, isc::dns::rdata::in::AAAA, and isc::dns::rdata::in::DHCID.

◆ getLength()

uint16_t isc::dns::rdata::Rdata::getLength ( ) const
virtual

Get the wire format length of an Rdata.

IMPLEMENTATION NOTE: Currently this base class implementation is non-optimal as it renders the wire data to a buffer and returns the buffer's length. What would perform better is to add implementations of getLength() method to every RDATA type. This is why this method is virtual. Once all Rdata types have getLength() implementations, this base class implementation must be removed and the method should become a pure interface.

Returns
The length of the wire format representation of the RDATA.

Definition at line 43 of file rdata.cc.

References toWire().

+ Here is the call graph for this function:

◆ toText()

virtual std::string isc::dns::rdata::Rdata::toText ( ) const
pure virtual

Convert an Rdata to a string.

This method returns a std::string object representing the Rdata.

This is a pure virtual method without the definition; the actual representation is specific to each derived concrete class and should be explicitly defined in the derived class.

Returns
A string representation of Rdata.

Implemented in isc::dns::rdata::generic::Generic, isc::dns::rdata::any::TSIG, isc::dns::rdata::ch::A, isc::dns::rdata::generic::NS, isc::dns::rdata::generic::OPT, isc::dns::rdata::generic::PTR, isc::dns::rdata::generic::RRSIG, isc::dns::rdata::generic::SOA, isc::dns::rdata::generic::TKEY, isc::dns::rdata::generic::TXT, isc::dns::rdata::in::A, isc::dns::rdata::in::AAAA, and isc::dns::rdata::in::DHCID.

◆ toWire() [1/2]

virtual void isc::dns::rdata::Rdata::toWire ( AbstractMessageRenderer & renderer) const
pure virtual

Render the Rdata in the wire format into a MessageRenderer object.

This is a pure virtual method without the definition; the actual conversion is specific to each derived concrete class and should be explicitly defined in the derived class.

Parameters
rendererDNS message rendering context that encapsulates the output buffer in which the Rdata is to be stored.

Implemented in isc::dns::rdata::generic::Generic, isc::dns::rdata::any::TSIG, isc::dns::rdata::ch::A, isc::dns::rdata::generic::NS, isc::dns::rdata::generic::OPT, isc::dns::rdata::generic::PTR, isc::dns::rdata::generic::RRSIG, isc::dns::rdata::generic::SOA, isc::dns::rdata::generic::TKEY, isc::dns::rdata::generic::TXT, isc::dns::rdata::in::A, isc::dns::rdata::in::AAAA, and isc::dns::rdata::in::DHCID.

◆ toWire() [2/2]

virtual void isc::dns::rdata::Rdata::toWire ( isc::util::OutputBuffer & buff) const
pure virtual

Render the Rdata in the wire format into a buffer.

This is a pure virtual method without the definition; the actual conversion is specific to each derived concrete class and should be explicitly defined in the derived class.

Parameters
buffAn output buffer to store the wire data.

Implemented in isc::dns::rdata::generic::Generic, isc::dns::rdata::any::TSIG, isc::dns::rdata::ch::A, isc::dns::rdata::generic::NS, isc::dns::rdata::generic::OPT, isc::dns::rdata::generic::PTR, isc::dns::rdata::generic::RRSIG, isc::dns::rdata::generic::SOA, isc::dns::rdata::generic::TKEY, isc::dns::rdata::generic::TXT, isc::dns::rdata::in::A, isc::dns::rdata::in::AAAA, and isc::dns::rdata::in::DHCID.

Referenced by getLength().


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