Kea: opaque_data_tuple.h Source File

| Kea 2.2.0

opaque_data_tuple.h
Go to the documentation of this file.
1// Copyright (C) 2014-2021 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#include <util/io_utilities.h>
13
14#include <iostream>
15#include <iterator>
16#include <string>
17#include <vector>
18
19namespace isc {
20namespace dhcp {
21
24 class OpaqueDataTupleError : public Exception {
25public:
26 OpaqueDataTupleError(const char* file, size_t line, const char* what) :
27 isc::Exception(file, line, what) { };
28};
29
30
47 class OpaqueDataTuple {
48public:
49
57 enum LengthFieldType {
58 LENGTH_1_BYTE,
59 LENGTH_2_BYTES
60 };
61
63 using Buffer = std::vector<uint8_t>;
64 using InputIterator = Buffer::const_iterator;
65
70 OpaqueDataTuple(LengthFieldType length_field_type);
71
83 OpaqueDataTuple(LengthFieldType length_field_type,
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(InputIterator data, const size_t len) {
107 data_.insert(data_.end(), data, data + len);
108 }
109
116 void append(const std::string& text);
117
128 void assign(const char* data, const size_t len) {
129 data_.assign(data, data + len);
130 }
131 void assign(InputIterator data, const size_t len) {
132 data_.assign(data, data + len);
133 }
134
141 void assign(const std::string& text);
142
144 void clear();
145
149 bool equals(const std::string& other) const;
150
152 LengthFieldType getLengthFieldType() const {
153 return (length_field_type_);
154 }
155
157 size_t getLength() const {
158 return (data_.size());
159 }
160
162 size_t getTotalLength() const {
163 return (getDataFieldSize() + getLength());
164 }
165
171 const Buffer& getData() const {
172 return (data_);
173 }
174
176 std::string getText() const;
177
199 void pack(isc::util::OutputBuffer& buf) const;
200
216 void unpack(InputIterator begin, InputIterator end);
217
219 //{@
220
227 OpaqueDataTuple& operator=(const std::string& other);
228
236 bool operator==(const std::string& other) const;
237
246 bool operator!=(const std::string& other);
248
252 int getDataFieldSize() const;
253
254private:
255
257 Buffer data_;
258
260 LengthFieldType length_field_type_;
261};
262
264 typedef boost::shared_ptr<OpaqueDataTuple> OpaqueDataTuplePtr;
265
275std::ostream& operator<<(std::ostream& os, const OpaqueDataTuple& tuple);
276
285std::istream& operator>>(std::istream& is, OpaqueDataTuple& tuple);
286
287} // namespace isc::dhcp
288} // namespace isc
289
290#endif
buffer.h
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::dhcp::OpaqueDataTupleError
Exception to be thrown when the operation on OpaqueDataTuple object results in an error.
Definition: opaque_data_tuple.h:24
isc::dhcp::OpaqueDataTupleError::OpaqueDataTupleError
OpaqueDataTupleError(const char *file, size_t line, const char *what)
Definition: opaque_data_tuple.h:26
isc::dhcp::OpaqueDataTuple
Represents a single instance of the opaque data preceded by length.
Definition: opaque_data_tuple.h:47
isc::dhcp::OpaqueDataTuple::operator==
bool operator==(const std::string &other) const
Equality operator.
Definition: opaque_data_tuple.cc:85
isc::dhcp::OpaqueDataTuple::clear
void clear()
Removes the contents of the tuple.
Definition: opaque_data_tuple.cc:37
isc::dhcp::OpaqueDataTuple::getDataFieldSize
int getDataFieldSize() const
Returns the size of the tuple length field.
Definition: opaque_data_tuple.cc:73
isc::dhcp::OpaqueDataTuple::operator=
OpaqueDataTuple & operator=(const std::string &other)
Assignment operator.
Definition: opaque_data_tuple.cc:78
isc::dhcp::OpaqueDataTuple::OpaqueDataTuple
OpaqueDataTuple(LengthFieldType length_field_type)
Default constructor.
Definition: opaque_data_tuple.cc:14
isc::dhcp::OpaqueDataTuple::assign
void assign(InputIterator data, const size_t len)
Definition: opaque_data_tuple.h:131
isc::dhcp::OpaqueDataTuple::getData
const Buffer & getData() const
Returns a reference to the buffer holding tuple data.
Definition: opaque_data_tuple.h:171
isc::dhcp::OpaqueDataTuple::LengthFieldType
LengthFieldType
Size of the length field in the tuple.
Definition: opaque_data_tuple.h:57
isc::dhcp::OpaqueDataTuple::LENGTH_2_BYTES
@ LENGTH_2_BYTES
Definition: opaque_data_tuple.h:59
isc::dhcp::OpaqueDataTuple::LENGTH_1_BYTE
@ LENGTH_1_BYTE
Definition: opaque_data_tuple.h:58
isc::dhcp::OpaqueDataTuple::pack
void pack(isc::util::OutputBuffer &buf) const
Renders the tuple to a buffer in the wire format.
Definition: opaque_data_tuple.cc:53
isc::dhcp::OpaqueDataTuple::append
void append(InputIterator data, const size_t len)
Definition: opaque_data_tuple.h:106
isc::dhcp::OpaqueDataTuple::getLengthFieldType
LengthFieldType getLengthFieldType() const
Returns tuple length data field type.
Definition: opaque_data_tuple.h:152
isc::dhcp::OpaqueDataTuple::InputIterator
Buffer::const_iterator InputIterator
Definition: opaque_data_tuple.h:64
isc::dhcp::OpaqueDataTuple::assign
void assign(const char *data, const size_t len)
Assigns data to the tuple.
Definition: opaque_data_tuple.h:128
isc::dhcp::OpaqueDataTuple::getText
std::string getText() const
Return the tuple data in the textual format.
Definition: opaque_data_tuple.cc:47
isc::dhcp::OpaqueDataTuple::getTotalLength
size_t getTotalLength() const
Returns a total size of the tuple, including length field.
Definition: opaque_data_tuple.h:162
isc::dhcp::OpaqueDataTuple::append
void append(const char *data, const size_t len)
Appends data to the tuple.
Definition: opaque_data_tuple.h:103
isc::dhcp::OpaqueDataTuple::equals
bool equals(const std::string &other) const
Checks if the data carried in the tuple match the string.
Definition: opaque_data_tuple.cc:42
isc::dhcp::OpaqueDataTuple::unpack
void unpack(InputIterator begin, InputIterator end)
Parses wire data and creates a tuple from it.
Definition: opaque_data_tuple.cc:116
isc::dhcp::OpaqueDataTuple::operator!=
bool operator!=(const std::string &other)
Inequality operator.
Definition: opaque_data_tuple.cc:90
isc::dhcp::OpaqueDataTuple::OpaqueDataTuple
OpaqueDataTuple(LengthFieldType length_field_type, InputIterator begin, InputIterator end)
Constructor.
Definition: opaque_data_tuple.h:83
isc::dhcp::OpaqueDataTuple::Buffer
std::vector< uint8_t > Buffer
Defines a type of the data buffer used to hold the opaque data.
Definition: opaque_data_tuple.h:63
isc::dhcp::OpaqueDataTuple::getLength
size_t getLength() const
Returns the length of the data in the tuple.
Definition: opaque_data_tuple.h:157
isc::util::OutputBuffer
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
io_utilities.h
isc::dhcp::operator>>
std::istream & operator>>(std::istream &is, OpaqueDataTuple &tuple)
Inserts data carried in the stream into the tuple.
Definition: opaque_data_tuple.cc:99
isc::dhcp::operator<<
std::ostream & operator<<(std::ostream &os, const OpaqueDataTuple &tuple)
Inserts the OpaqueDataTuple as a string into stream.
Definition: opaque_data_tuple.cc:94
isc::dhcp::OpaqueDataTuplePtr
boost::shared_ptr< OpaqueDataTuple > OpaqueDataTuplePtr
Pointer to the OpaqueDataTuple object.
Definition: opaque_data_tuple.h:264
isc
Defines the logger used by the top-level component of kea-lfc.
Definition: agent_parser.cc:143
option.h