Kea 3.3.3
messagerenderer.h
Go to the documentation of this file.
1// Copyright (C) 2009-2026 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 <cstdint>
13#include <memory>
14
15#include <boost/noncopyable.hpp>
16
17namespace isc {
18namespace dns {
19// forward declarations
20class Name;
21class LabelSequence;
22
71public:
99protected:
102
103
108
109public:
113protected:
115 const isc::util::OutputBuffer& getBuffer() const { return (*buffer_); }
116 isc::util::OutputBuffer& getBuffer() { return (*buffer_); }
117private:
119 isc::util::OutputBuffer local_buffer_;
120
131public:
135
136
141 const void* getData() const {
142 return (buffer_->getData());
143 }
144
146 size_t getLength() const {
147 return (buffer_->getLength());
148 }
149
159 virtual bool isTruncated() const = 0;
160
167 virtual size_t getLengthLimit() const = 0;
168
174 virtual CompressMode getCompressMode() const = 0;
176
180
181
209
214 virtual void setTruncated() = 0;
215
222 virtual void setLengthLimit(size_t len) = 0;
223
229 virtual void setCompressMode(CompressMode mode) = 0;
231
235
236
243 void skip(size_t len) {
244 buffer_->skip(len);
245 }
246
257 void trim(size_t len) {
258 buffer_->trim(len);
259 }
260
265 virtual void clear();
266
270 void writeUint8(const uint8_t data) {
271 buffer_->writeUint8(data);
272 }
273
278 void writeUint16(uint16_t data) {
279 buffer_->writeUint16(data);
280 }
281
292 void writeUint16At(uint16_t data, size_t pos) {
293 buffer_->writeUint16At(data, pos);
294 }
295
300 void writeUint32(uint32_t data) {
301 buffer_->writeUint32(data);
302 }
303
311 void writeData(const void *data, size_t len) {
312 buffer_->writeData(data, len);
313 }
314
330 virtual void writeName(const Name& name, bool compress = true) = 0;
331
342 virtual void writeName(const LabelSequence& ls, bool compress = true) = 0;
344};
345
358 public boost::noncopyable { // Can crash if copied
359public:
362
364
365 virtual ~MessageRenderer();
366 virtual bool isTruncated() const;
367 virtual size_t getLengthLimit() const;
368 virtual CompressMode getCompressMode() const;
369 virtual void setTruncated();
370 virtual void setLengthLimit(size_t len);
371
380 virtual void setCompressMode(CompressMode mode);
381
382 virtual void clear();
383 virtual void writeName(const Name& name, bool compress = true);
384 virtual void writeName(const LabelSequence& ls, bool compress = true);
385
386private:
387 struct MessageRendererImpl;
388 std::unique_ptr<MessageRendererImpl> impl_;
389};
390}
391}
392#endif // MESSAGERENDERER_H
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 ...
CompressMode
Compression mode constants.
@ CASE_SENSITIVE
Compress names case-sensitive manner.
@ CASE_INSENSITIVE
Compress names case-insensitive manner (default).
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.
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.
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:217
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:355
Defines the logger used by the top-level component of kea-lfc.
The MessageRendererImpl class is the actual implementation of MessageRenderer.