Kea  1.9.9-git
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 
14 namespace isc {
15 
16 namespace dns {
17 // forward declarations
18 class Name;
19 class LabelSequence;
20 
69 public:
93  enum CompressMode {
96  };
97 protected:
100 
106 
107 public:
111 protected:
113  const isc::util::OutputBuffer& getBuffer() const { return (*buffer_); }
114  isc::util::OutputBuffer& getBuffer() { return (*buffer_); }
115 private:
117  isc::util::OutputBuffer local_buffer_;
118 
128  isc::util::OutputBuffer* buffer_;
129 public:
133 
134  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  void setBuffer(isc::util::OutputBuffer* buffer);
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  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
358 public:
361 
362  MessageRenderer();
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 
385 private:
386  struct MessageRendererImpl;
387  MessageRendererImpl* impl_;
388 };
389 }
390 }
391 #endif // MESSAGERENDERER_H
392 
393 // Local Variables:
394 // mode: c++
395 // End:
void setBuffer(isc::util::OutputBuffer *buffer)
Set or reset a temporary output buffer.
The Name class encapsulates DNS names.
Definition: name.h:223
void writeUint8(const uint8_t data)
Write an unsigned 8-bit integer into the internal buffer.
virtual void setLengthLimit(size_t len)
Set the maximum length of rendered data that can fit in the corresponding DNS message without truncat...
const void * getData() const
Return a pointer to the head of the data stored in the buffer.
Definition: buffer.h:401
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 skip(size_t len)
Insert a specified length of gap at the end of the buffer.
virtual void setTruncated()
Mark the renderer to indicate truncation has occurred while rendering.
virtual bool isTruncated() const =0
Return whether truncation has occurred while rendering.
void skip(size_t len)
Insert a specified length of gap at the end of the buffer.
Definition: buffer.h:429
AbstractMessageRenderer()
The default constructor.
virtual void clear()
Clear the internal buffer and other internal resources.
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 ...
The MessageRendererImpl class is the actual implementation of MessageRenderer.
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the internal buffer in network byte order...
virtual bool isTruncated() const
Return whether truncation has occurred while rendering.
isc::util::OutputBuffer & getBuffer()
void trim(size_t len)
Trim the specified length of data from the end of the internal buffer.
void trim(size_t len)
Trim the specified length of data from the end of the buffer.
Definition: buffer.h:441
virtual void clear()
Clear the internal buffer and other internal resources.
void writeUint16(uint16_t data)
Write an unsigned 16-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 buffer.
Definition: buffer.h:550
void writeUint16At(uint16_t data, size_t pos)
Write an unsigned 16-bit integer in host byte order at the specified position of the buffer in networ...
Definition: buffer.h:507
const void * getData() const
Return a pointer to the head of the data stored in the internal buffer.
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
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 void setTruncated()=0
Mark the renderer to indicate truncation has occurred while rendering.
CompressMode
Compression mode constants.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the internal buffer of the renderer object. ...
virtual void setCompressMode(CompressMode mode)=0
Set the compression mode of the renderer class object.
Compress names case-sensitive manner.
virtual ~AbstractMessageRenderer()
The destructor.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the buffer in network byte order...
Definition: buffer.h:520
Defines the logger used by the top-level component of kea-dhcp-ddns.
const isc::util::OutputBuffer & getBuffer() const
Return the output buffer we render into.
virtual CompressMode getCompressMode() const
Return the compression mode of the renderer class object.
virtual size_t getLengthLimit() const
Return the maximum length of rendered data that can fit in the corresponding DNS message without trun...
The MessageRenderer is a concrete derived class of AbstractMessageRenderer as a general purpose imple...
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
Definition: buffer.h:466
Compress names case-insensitive manner (default)
virtual void setLengthLimit(size_t len)=0
Set the maximum length of rendered data that can fit in the corresponding DNS message without truncat...
virtual void setCompressMode(CompressMode mode)
This implementation does not allow this call in the middle of rendering (i.e.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order...
Definition: buffer.h:490
size_t getLength() const
Return the length of data written in the internal buffer.
virtual size_t getLengthLimit() const =0
Return the maximum length of rendered data that can fit in the corresponding DNS message without trun...
size_t getLength() const
Return the length of data written in the buffer.
Definition: buffer.h:403
Light-weight Accessor to Name data.
Definition: labelsequence.h:35
virtual CompressMode getCompressMode() const =0
Return the compression mode of the renderer class object.