Kea 2.2.0
messagerenderer.h
Go to the documentation of this file.
1// Copyright (C) 2009-2017 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 1
9
10#include <util/buffer.h>
11
12#include <boost/noncopyable.hpp>
13
14namespace isc {
15
16namespace dns {
17// forward declarations
18class Name;
19class LabelSequence;
20
69public:
96 };
97protected:
100
101
106
107public:
111protected:
113 const isc::util::OutputBuffer& getBuffer() const { return (*buffer_); }
114 isc::util::OutputBuffer& getBuffer() { return (*buffer_); }
115private:
117 isc::util::OutputBuffer local_buffer_;
118
129public:
133
134
139 const void* getData() const {
140 return (buffer_->getData());
141 }
142
144 size_t getLength() const {
145 return (buffer_->getLength());
146 }
147
157 virtual bool isTruncated() const = 0;
158
165 virtual size_t getLengthLimit() const = 0;
166
172 virtual CompressMode getCompressMode() const = 0;
174
178
179
207
212 virtual void setTruncated() = 0;
213
220 virtual void setLengthLimit(size_t len) = 0;
221
227 virtual void setCompressMode(CompressMode mode) = 0;
229
233
234
241 void skip(size_t len) {
242 buffer_->skip(len);
243 }
244
255 void trim(size_t len) {
256 buffer_->trim(len);
257 }
258
263 virtual void clear();
264
268 void writeUint8(const uint8_t data) {
269 buffer_->writeUint8(data);
270 }
271
276 void writeUint16(uint16_t data) {
277 buffer_->writeUint16(data);
278 }
279
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 MessageRendererImpl* impl_;
388};
389}
390}
391#endif // MESSAGERENDERER_H
392
393// Local Variables:
394// mode: c++
395// End:
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.
Definition: labelsequence.h:35
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:223
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
Defines the logger used by the top-level component of kea-lfc.
The MessageRendererImpl class is the actual implementation of MessageRenderer.