The MessageRenderer
class encapsulates implementation details of rendering a DNS message into a buffer in wire format.
More...
Public Member Functions | |
Constructors and Destructor | |
MessageRenderer (OutputBuffer &buffer) | |
Constructor from an output buffer. | |
~MessageRenderer () | |
The default destructor. | |
Rendering Methods | |
| |
void | writeName (const Name &name, bool compress=true) |
Write a Name object into the internal buffer in wire format, with or without name compression. |
The MessageRenderer
class encapsulates implementation details of rendering a DNS message into a buffer in wire format.
In effect, it's simply responsible for name compression at least in the current implementation. A MessageRenderer
class object manages the positions of names rendered in a buffer and uses that information to render subsequent names with compression.
This class is mainly intended to be used as a helper for a more comprehensive Message
class internally; normal applications won't have to care about this class.
A MessageRenderer
class object is constructed with a OutputBuffer
object, which is the buffer into which the rendered data will be written. Normally the buffer is expected to be empty on construction, but it doesn't have to be so; the MessageRenderer
object will start rendering from the end of the buffer at the time of construction. However, if the pre-existing portion of the buffer contains DNS names, these names won't be considered for name compression.
Once a MessageRenderer
object is constructed with a buffer, it is generally expected that all rendering operations are performed via the MessageRenderer
object. If the application modifies the buffer in parallel with the MessageRenderer
, the result will be undefined.
Note to developers: we introduced a separate class for name compression because previous benchmark with BIND9 showed compression affects overall response performance very much. By having a separate class dedicated for this purpose, we'll be able to change the internal implementation of name compression in the future without affecting other part of the API and implementation. For the same reason, we adopt the "pimpl" idiom in the class definition (i.e., using a pointer to a MessageRendererImpl
class, which is defined with the class implementation, not in the header file): we may want to modify the compression implementation without modifying the header file thereby requesting rebuild the package.
Furthermore, we may eventually want to allow other developers to develop and use their own compression implementation. Should such a case become realistic, we may want to make the MessageRendererImpl
class an abstract base class and let concrete derived classes have their own implementations. At the moment we don't the strong need for it, so we rather avoid over abstraction and keep the definition simpler.
isc::dns::MessageRenderer::MessageRenderer | ( | OutputBuffer & | buffer | ) |
Constructor from an output buffer.
buffer | An OutputBuffer object to which wire format data is written. |
isc::dns::MessageRenderer::~MessageRenderer | ( | ) |
The default destructor.
The destructor does nothing on the given buffer
on construction; in fact, it is expected that the user will use the resulting buffer for some post rendering purposes (e.g., send the data to the network). It's user's responsibility to do any necessary cleanup for the buffer
.
void isc::dns::MessageRenderer::writeName | ( | const Name & | name, | |
bool | compress = true | |||
) |
Write a Name
object into the internal buffer in wire format, with or without name compression.
If the optional parameter compress
is true
, this method tries to compress the name
if possible, searching the entire message that has been rendered. Otherwise name compression is omitted. Its default value is true
.
Note: even if compress
is true
, the position of the name
(and possibly its ancestor names) in the message is recorded and may be used for compressing subsequent names.
name | A Name object to be written. | |
compress | A boolean indicating whether to enable name compression. |
References isc::dns::MessageRendererImpl::buffer_, isc::dns::OutputBuffer::clear(), isc::dns::Name::COMPRESS_POINTER_MARK16, isc::dns::OutputBuffer::getData(), isc::dns::OutputBuffer::getLength(), isc::dns::Name::MAX_COMPRESS_POINTER, isc::dns::MessageRendererImpl::nbuffer_, isc::dns::MessageRendererImpl::nodeset_, isc::dns::Name::toWire(), isc::dns::OutputBuffer::writeData(), and isc::dns::OutputBuffer::writeUint16().
Referenced by isc::dns::Name::toWire().