Kea 2.5.8
opaque_data_tuple.h
Go to the documentation of this file.
1// Copyright (C) 2014-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 OPAQUE_DATA_TUPLE_H
8#define OPAQUE_DATA_TUPLE_H
9
10#include <dhcp/option.h>
11#include <util/buffer.h>
12
13#include <iostream>
14#include <iterator>
15#include <string>
16#include <vector>
17
18namespace isc {
19namespace dhcp {
20
24public:
25 OpaqueDataTupleError(const char* file, size_t line, const char* what) :
26 isc::Exception(file, line, what) { };
27};
28
29
47public:
48
60 };
61
63 using Buffer = std::vector<uint8_t>;
64 using InputIterator = Buffer::const_iterator;
65
70 OpaqueDataTuple(LengthFieldType length_field_type);
71
84 InputIterator begin,
85 InputIterator end)
86 : length_field_type_(length_field_type) {
87 unpack(begin, end);
88 }
89
103 void append(const char* data, const size_t len) {
104 data_.insert(data_.end(), data, data + len);
105 }
106 void append(const uint8_t* data, const size_t len) {
107 data_.insert(data_.end(), data, data + len);
108 }
109 void append(InputIterator data, const size_t len) {
110 data_.insert(data_.end(), data, data + len);
111 }
112
119 void append(const std::string& text);
120
131 void assign(const char* data, const size_t len) {
132 data_.assign(data, data + len);
133 }
134 void assign(InputIterator data, const size_t len) {
135 data_.assign(data, data + len);
136 }
137
144 void assign(const std::string& text);
145
147 void clear();
148
152 bool equals(const std::string& other) const;
153
156 return (length_field_type_);
157 }
158
160 size_t getLength() const {
161 return (data_.size());
162 }
163
165 size_t getTotalLength() const {
166 return (getDataFieldSize() + getLength());
167 }
168
174 const Buffer& getData() const {
175 return (data_);
176 }
177
179 std::string getText() const;
180
202 void pack(isc::util::OutputBuffer& buf) const;
203
219 void unpack(InputIterator begin, InputIterator end);
220
222 //{@
223
230 OpaqueDataTuple& operator=(const std::string& other);
231
239 bool operator==(const std::string& other) const;
240
249 bool operator!=(const std::string& other);
251
255 int getDataFieldSize() const;
256
257private:
258
260 Buffer data_;
261
263 LengthFieldType length_field_type_;
264};
265
267typedef boost::shared_ptr<OpaqueDataTuple> OpaqueDataTuplePtr;
268
278std::ostream& operator<<(std::ostream& os, const OpaqueDataTuple& tuple);
279
288std::istream& operator>>(std::istream& is, OpaqueDataTuple& tuple);
289
290} // namespace isc::dhcp
291} // namespace isc
292
293#endif
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception to be thrown when the operation on OpaqueDataTuple object results in an error.
OpaqueDataTupleError(const char *file, size_t line, const char *what)
Represents a single instance of the opaque data preceded by length.
bool operator==(const std::string &other) const
Equality operator.
void clear()
Removes the contents of the tuple.
int getDataFieldSize() const
Returns the size of the tuple length field.
OpaqueDataTuple & operator=(const std::string &other)
Assignment operator.
void assign(InputIterator data, const size_t len)
const Buffer & getData() const
Returns a reference to the buffer holding tuple data.
LengthFieldType
Size of the length field in the tuple.
void pack(isc::util::OutputBuffer &buf) const
Renders the tuple to a buffer in the wire format.
void append(InputIterator data, const size_t len)
LengthFieldType getLengthFieldType() const
Returns tuple length data field type.
Buffer::const_iterator InputIterator
void assign(const char *data, const size_t len)
Assigns data to the tuple.
std::string getText() const
Return the tuple data in the textual format.
size_t getTotalLength() const
Returns a total size of the tuple, including length field.
void append(const char *data, const size_t len)
Appends data to the tuple.
void append(const uint8_t *data, const size_t len)
bool equals(const std::string &other) const
Checks if the data carried in the tuple match the string.
void unpack(InputIterator begin, InputIterator end)
Parses wire data and creates a tuple from it.
bool operator!=(const std::string &other)
Inequality operator.
OpaqueDataTuple(LengthFieldType length_field_type, InputIterator begin, InputIterator end)
Constructor.
std::vector< uint8_t > Buffer
Defines a type of the data buffer used to hold the opaque data.
size_t getLength() const
Returns the length of the data in the tuple.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:347
std::istream & operator>>(std::istream &is, OpaqueDataTuple &tuple)
Inserts data carried in the stream into the tuple.
boost::shared_ptr< OpaqueDataTuple > OpaqueDataTuplePtr
Pointer to the OpaqueDataTuple object.
Defines the logger used by the top-level component of kea-lfc.