Kea  2.1.7-git
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

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

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. More...
 
virtual ~Rdata ()
 The destructor. More...
 

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

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

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 123 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 139 of file rdata.h.

◆ ~Rdata()

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

The destructor.

Definition at line 145 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::in::SRV, isc::dns::rdata::in::DHCID, isc::dns::rdata::in::AAAA, isc::dns::rdata::in::A, isc::dns::rdata::hs::A, isc::dns::rdata::generic::TXT, isc::dns::rdata::generic::TLSA, isc::dns::rdata::generic::TKEY, isc::dns::rdata::generic::SSHFP, isc::dns::rdata::generic::SPF, isc::dns::rdata::generic::SOA, isc::dns::rdata::generic::RRSIG, isc::dns::rdata::generic::RP, isc::dns::rdata::generic::PTR, isc::dns::rdata::generic::OPT, isc::dns::rdata::generic::NSEC, isc::dns::rdata::generic::NSEC3PARAM, isc::dns::rdata::generic::NSEC3, isc::dns::rdata::generic::NS, isc::dns::rdata::generic::NAPTR, isc::dns::rdata::generic::MX, isc::dns::rdata::generic::MINFO, isc::dns::rdata::generic::HINFO, isc::dns::rdata::generic::DS, isc::dns::rdata::generic::DNSKEY, isc::dns::rdata::generic::DNAME, isc::dns::rdata::generic::DLV, isc::dns::rdata::generic::CNAME, isc::dns::rdata::generic::CAA, isc::dns::rdata::generic::Generic, isc::dns::rdata::generic::AFSDB, isc::dns::rdata::ch::A, and isc::dns::rdata::any::TSIG.

◆ 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 45 of file rdata.cc.

References isc::util::OutputBuffer::getLength().

+ Here is the call graph for this function:

◆ toText()

◆ toWire() [1/2]

◆ toWire() [2/2]

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

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