Kea 3.3.3
opaque_data_tuple.h
Go to the documentation of this file.
1// Copyright (C) 2014-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 OPAQUE_DATA_TUPLE_H
8#define OPAQUE_DATA_TUPLE_H
9
10#include <dhcp/option.h>
11#include <util/buffer.h>
12
13#include <cstdint>
14#include <iostream>
15#include <iterator>
16#include <string>
17#include <vector>
18
19namespace isc {
20namespace dhcp {
21
25public:
26 OpaqueDataTupleError(const char* file, size_t line, const char* what) :
27 isc::Exception(file, line, what) { }
28};
29
30
48public:
49
57 enum LengthFieldType : int16_t {
61 };
62
64 using Buffer = std::vector<uint8_t>;
65 using InputIterator = Buffer::const_iterator;
66
71 OpaqueDataTuple(LengthFieldType length_field_type);
72
85 InputIterator begin,
86 InputIterator end)
87 : length_field_type_(length_field_type) {
88 unpack(begin, end);
89 }
90
104 void append(const char* data, const size_t len) {
105 data_.insert(data_.end(), data, data + len);
106 }
107 void append(const uint8_t* data, const size_t len) {
108 data_.insert(data_.end(), data, data + len);
109 }
110 void append(InputIterator data, const size_t len) {
111 data_.insert(data_.end(), data, data + len);
112 }
113
120 void append(const std::string& text);
121
132 void assign(const char* data, const size_t len) {
133 data_.assign(data, data + len);
134 }
135 void assign(InputIterator data, const size_t len) {
136 data_.assign(data, data + len);
137 }
138
145 void assign(const std::string& text);
146
148 void clear();
149
153 bool equals(const std::string& other) const;
154
157 return (length_field_type_);
158 }
159
161 size_t getLength() const {
162 return (data_.size());
163 }
164
166 size_t getTotalLength() const {
167 return (getDataFieldSize() + getLength());
168 }
169
175 const Buffer& getData() const {
176 return (data_);
177 }
178
180 std::string getText() const;
181
203 void pack(isc::util::OutputBuffer& buf) const;
204
220 void unpack(InputIterator begin, InputIterator end);
221
223 //{@
224
231 OpaqueDataTuple& operator=(const std::string& other);
232
240 bool operator==(const std::string& other) const;
241
250 bool operator!=(const std::string& other);
252
256 int getDataFieldSize() const;
257
258private:
259
261 Buffer data_;
262
264 LengthFieldType length_field_type_;
265};
266
268typedef boost::shared_ptr<OpaqueDataTuple> OpaqueDataTuplePtr;
269
279std::ostream& operator<<(std::ostream& os, const OpaqueDataTuple& tuple);
280
289std::istream& operator>>(std::istream& is, OpaqueDataTuple& tuple);
290
291} // namespace isc::dhcp
292} // namespace isc
293
294#endif
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
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.
OpaqueDataTuple(LengthFieldType length_field_type)
Default constructor.
void assign(InputIterator data, const size_t len)
const Buffer & getData() const
Returns a reference to the buffer holding tuple data.
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.
LengthFieldType
Size of the length field in the tuple.
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:355
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.