41 const uint8_t* data,
size_t data_length) :
42 allocated_fields_(fields),
43 allocated_data_(data, data + data_length)
67 RdataFieldComposer() :
71 virtual ~RdataFieldComposer() {}
72 virtual bool isTruncated()
const {
return (
truncated_); }
73 virtual size_t getLengthLimit()
const {
return (
length_limit_); }
74 virtual CompressMode getCompressMode()
const {
return (
mode_); }
75 virtual void setTruncated() {
truncated_ =
true; }
76 virtual void setLengthLimit(
size_t len) {
length_limit_ = len; }
77 virtual void setCompressMode(CompressMode mode) {
mode_ = mode; }
79 virtual void writeName(
const Name& name,
bool compress) {
82 compress ? RdataFields::COMPRESSIBLE_NAME :
83 RdataFields::INCOMPRESSIBLE_NAME;
92 virtual void clear() {
99 vector<RdataFields::FieldSpec>& getFields() {
109 if (getLength() == last_data_pos_) {
113 if (fields_.empty() || fields_.back().type != RdataFields::DATA) {
118 last_data_pos_ = getLength();
124 RdataFields::RdataFields(
const Rdata& rdata) {
125 RdataFieldComposer field_composer;
126 rdata.
toWire(field_composer);
127 nfields_ = field_composer.getFields().size();
128 data_length_ = field_composer.getLength();
130 assert(data_length_ > 0);
132 static_cast<const uint8_t*
>
133 (field_composer.getData()),
134 field_composer.getLength());
136 fields_ = &detail_->allocated_fields_[0];
138 assert(data_length_ == 0);
145 RdataFields::RdataFields(
const void* fields,
const unsigned int fields_length,
146 const void* data,
const size_t data_length) :
148 nfields_(fields_length / sizeof(*
fields_)),
149 data_(static_cast<const uint8_t*>(data)),
150 data_length_(data_length),
153 if ((fields_ == NULL && nfields_ > 0) ||
154 (fields_ != NULL && nfields_ == 0)) {
156 "Inconsistent parameters for RdataFields: fields_length ("
157 << fields_length <<
") and fields conflict each other");
159 if ((data_ == NULL && data_length_ > 0) ||
160 (data_ != NULL && data_length_ == 0)) {
162 "Inconsistent parameters for RdataFields: data length ("
163 << data_length_ <<
") and data conflict each other");
166 size_t total_length = 0;
167 for (
unsigned int i = 0; i < nfields_; ++i) {
168 total_length += fields_[i].
len;
170 if (total_length != data_length_) {
172 "Inconsistent parameters for RdataFields: "
173 "fields len: " << total_length <<
174 " data len: " << data_length_);
184 if (field_id >= nfields_) {
187 return (fields_[field_id]);
194 for (
unsigned int i = 0; i < nfields_; ++i) {
195 if (fields_[i].type ==
DATA) {
196 renderer.
writeData(data_ + offset, fields_[i].len);
202 InputBuffer buffer(data_ + offset, fields_[i].len);
206 offset += fields_[i].
len;
The Name class encapsulates DNS names.
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...
Type
Types of RdataFields fields.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
const vector< uint8_t > allocated_data_
The Rdata class is an abstract base class that provides a set of common interfaces to manipulate conc...
void toWire(AbstractMessageRenderer &renderer) const
Render the RdataFields in the wire format with name compression.
const vector< FieldSpec > allocated_fields_
virtual void toWire(isc::util::OutputBuffer &buffer) const =0
Render the Rdata in the wire format into a buffer.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
Structure that specifies a single RdataFields field.
A generic exception that is thrown when an unexpected error condition occurs.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the internal buffer of the renderer object. ...
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Defines the logger used by the top-level component of kea-dhcp-ddns.
A domain name subject to name compression.
vector< RdataFields::FieldSpec > fields_
size_t getLength() const
Gets the length of the Name in its wire format.
RdataFieldsDetail(const vector< FieldSpec > &fields, const uint8_t *data, size_t data_length)
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
uint16_t len
The length of the field in bytes.
void toWire(AbstractMessageRenderer &renderer) const
Render the Name in the wire format with compression.
~RdataFields()
The destructor.
FieldSpec getFieldSpec(const unsigned int field_id) const
Return the specification of the field identified by the given index.
Light-weight Accessor to Name data.
This is a helper class for RdataFields.