Kea 2.7.5
messagerenderer.h
Go to the documentation of this file.
1// Copyright (C) 2009-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef MESSAGERENDERER_H
8#define MESSAGERENDERER_H
9
10#include <util/buffer.h>
11
12#include <boost/noncopyable.hpp>
13
14#include <memory>
15
16namespace isc {
17namespace dns {
18// forward declarations
19class Name;
20class LabelSequence;
21
70public:
98protected:
101
102
107
108public:
112protected:
114 const isc::util::OutputBuffer& getBuffer() const { return (*buffer_); }
115 isc::util::OutputBuffer& getBuffer() { return (*buffer_); }
116private:
118 isc::util::OutputBuffer local_buffer_;
119
130public:
134
135
140 const void* getData() const {
141 return (buffer_->getData());
142 }
143
145 size_t getLength() const {
146 return (buffer_->getLength());
147 }
148
158 virtual bool isTruncated() const = 0;
159
166 virtual size_t getLengthLimit() const = 0;
167
173 virtual CompressMode getCompressMode() const = 0;
175
179
180
208
213 virtual void setTruncated() = 0;
214
221 virtual void setLengthLimit(size_t len) = 0;
222
228 virtual void setCompressMode(CompressMode mode) = 0;
230
234
235
242 void skip(size_t len) {
243 buffer_->skip(len);
244 }
245
256 void trim(size_t len) {
257 buffer_->trim(len);
258 }
259
264 virtual void clear();
265
269 void writeUint8(const uint8_t data) {
270 buffer_->writeUint8(data);
271 }
272
277 void writeUint16(uint16_t data) {
278 buffer_->writeUint16(data);
279 }
280
291 void writeUint16At(uint16_t data, size_t pos) {
292 buffer_->writeUint16At(data, pos);
293 }
294
299 void writeUint32(uint32_t data) {
300 buffer_->writeUint32(data);
301 }
302
310 void writeData(const void *data, size_t len) {
311 buffer_->writeData(data, len);
312 }
313
329 virtual void writeName(const Name& name, bool compress = true) = 0;
330
341 virtual void writeName(const LabelSequence& ls, bool compress = true) = 0;
343};
344
357 public boost::noncopyable { // Can crash if copied
358public:
361
363
364 virtual ~MessageRenderer();
365 virtual bool isTruncated() const;
366 virtual size_t getLengthLimit() const;
367 virtual CompressMode getCompressMode() const;
368 virtual void setTruncated();
369 virtual void setLengthLimit(size_t len);
370
379 virtual void setCompressMode(CompressMode mode);
380
381 virtual void clear();
382 virtual void writeName(const Name& name, bool compress = true);
383 virtual void writeName(const LabelSequence& ls, bool compress = true);
384
385private:
386 struct MessageRendererImpl;
387 std::unique_ptr<MessageRendererImpl> impl_;
388};
389}
390}
391#endif // MESSAGERENDERER_H
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
AbstractMessageRenderer()
The default constructor.
virtual void setTruncated()=0
Mark the renderer to indicate truncation has occurred while rendering.
virtual void setLengthLimit(size_t len)=0
Set the maximum length of rendered data that can fit in the corresponding DNS message without truncat...
void trim(size_t len)
Trim the specified length of data from the end of the internal buffer.
virtual void writeName(const LabelSequence &ls, bool compress=true)=0
Write a LabelSequence object into the internal buffer in wire format, with or without name compressio...
size_t getLength() const
Return the length of data written in the internal buffer.
virtual void clear()
Clear the internal buffer and other internal resources.
virtual size_t getLengthLimit() const =0
Return the maximum length of rendered data that can fit in the corresponding DNS message without trun...
virtual void setCompressMode(CompressMode mode)=0
Set the compression mode of the renderer class object.
const void * getData() const
Return a pointer to the head of the data stored in the internal buffer.
virtual ~AbstractMessageRenderer()
The destructor.
virtual CompressMode getCompressMode() const =0
Return the compression mode of the renderer class object.
virtual bool isTruncated() const =0
Return whether truncation has occurred while rendering.
const isc::util::OutputBuffer & getBuffer() const
Return the output buffer we render into.
void skip(size_t len)
Insert a specified length of gap at the end of the buffer.
void writeUint16At(uint16_t data, size_t pos)
Write an unsigned 16-bit integer in host byte order at the specified position of the internal buffer ...
virtual void writeName(const Name &name, bool compress=true)=0
Write a Name object into the internal buffer in wire format, with or without name compression.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the internal buffer in network byte order.
CompressMode
Compression mode constants.
@ CASE_SENSITIVE
Compress names case-sensitive manner.
@ CASE_INSENSITIVE
Compress names case-insensitive manner (default)
void setBuffer(isc::util::OutputBuffer *buffer)
Set or reset a temporary output buffer.
void writeUint8(const uint8_t data)
Write an unsigned 8-bit integer into the internal buffer.
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the internal buffer in network byte order.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the internal buffer of the renderer object.
isc::util::OutputBuffer & getBuffer()
Light-weight Accessor to Name data.
The MessageRenderer is a concrete derived class of AbstractMessageRenderer as a general purpose imple...
virtual CompressMode getCompressMode() const
Return the compression mode of the renderer class object.
virtual void setLengthLimit(size_t len)
Set the maximum length of rendered data that can fit in the corresponding DNS message without truncat...
virtual void clear()
Clear the internal buffer and other internal resources.
virtual void setTruncated()
Mark the renderer to indicate truncation has occurred while rendering.
virtual bool isTruncated() const
Return whether truncation has occurred while rendering.
virtual void writeName(const Name &name, bool compress=true)
Write a Name object into the internal buffer in wire format, with or without name compression.
virtual size_t getLengthLimit() const
Return the maximum length of rendered data that can fit in the corresponding DNS message without trun...
virtual void setCompressMode(CompressMode mode)
This implementation does not allow this call in the middle of rendering (i.e.
The Name class encapsulates DNS names.
Definition name.h:219
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:343
Defines the logger used by the top-level component of kea-lfc.
The MessageRendererImpl class is the actual implementation of MessageRenderer.