7 #ifndef OPTION_DATA_TYPES_H 8 #define OPTION_DATA_TYPES_H 93 static const bool valid =
false;
94 static const int len = 0;
95 static const bool integer_type =
false;
102 static const bool valid =
true;
103 static const int len = 0;
104 static const bool integer_type =
false;
111 static const bool valid =
true;
112 static const int len =
sizeof(uint8_t);
113 static const bool integer_type =
false;
120 static const bool valid =
true;
121 static const int len = 1;
122 static const bool integer_type =
true;
129 static const bool valid =
true;
130 static const int len = 2;
131 static const bool integer_type =
true;
138 static const bool valid =
true;
139 static const int len = 4;
140 static const bool integer_type =
true;
147 static const bool valid =
true;
148 static const int len = 1;
149 static const bool integer_type =
true;
156 static const bool valid =
true;
157 static const int len = 2;
158 static const bool integer_type =
true;
165 static const bool valid =
true;
166 static const int len = 4;
167 static const bool integer_type =
true;
174 static const bool valid =
true;
182 static const int len = 0;
183 static const bool integer_type =
false;
190 static const bool valid =
true;
195 static const int len = 0;
196 static const bool integer_type =
false;
215 : psid_len_(psid_len) {
216 if (psid_len_ >
sizeof(uint16_t) * 8) {
218 << asUnsigned() <<
" of PSID length");
236 return (static_cast<unsigned>(psid_len_));
257 explicit PSID(
const uint16_t psid)
291 : prefix_len_(prefix_len) {
296 return (prefix_len_);
305 return (static_cast<unsigned>(prefix_len_));
341 static const std::string& getDataTypeName(
const OptionDataType data_type);
377 std::vector<uint8_t>& buf);
384 static void writeBinary(
const std::string& hex_str,
385 std::vector<uint8_t>& buf);
394 static std::string readTuple(
const std::vector<uint8_t>& buf,
404 static void readTuple(
const std::vector<uint8_t>& buf,
412 static void writeTuple(
const std::string& value,
414 std::vector<uint8_t>& buf);
421 std::vector<uint8_t>& buf);
430 static bool readBool(
const std::vector<uint8_t>& buf);
439 static void writeBool(
const bool value, std::vector<uint8_t>& buf);
450 static T
readInt(
const std::vector<uint8_t>& buf) {
453 " by readInteger is unsupported integer type");
458 "failed to read an integer value from a buffer" 459 <<
" - buffer is truncated.");
465 value = *(buf.begin());
481 "invalid size of the data type to be read as integer.");
493 std::vector<uint8_t>& buf) {
499 buf.push_back(static_cast<uint8_t>(value));
502 buf.resize(buf.size() + 2);
506 buf.resize(buf.size() + 4);
527 static std::string readFqdn(
const std::vector<uint8_t>& buf);
543 static void writeFqdn(
const std::string& fqdn,
544 std::vector<uint8_t>& buf,
545 const bool downcase =
false);
556 static unsigned int getLabelCount(
const std::string& text_name);
568 static PrefixTuple readPrefix(
const std::vector<uint8_t>& buf);
578 static void writePrefix(
const PrefixLen& prefix_len,
580 std::vector<uint8_t>& buf);
591 static PSIDTuple readPsid(
const std::vector<uint8_t>& buf);
608 static void writePsid(
const PSIDLen& psid_len,
const PSID& psid,
609 std::vector<uint8_t>& buf);
618 static std::string readString(
const std::vector<uint8_t>& buf);
624 static void writeString(
const std::string& value,
625 std::vector<uint8_t>& buf);
630 std::map<std::string, OptionDataType> data_types_;
634 std::map<OptionDataType, std::string> data_type_names_;
656 OptionDataType getDataTypeImpl(
const std::string& data_type)
const;
662 const std::string& getDataTypeNameImpl(
const OptionDataType data_type)
const;
669 #endif // OPTION_DATA_TYPES_H Encapsulation of option definition parameters and the structure size.
PrefixLen(const uint8_t prefix_len)
Constructor.
const char * encapsulates
Encapsulates PSID length.
uint8_t * writeUint32(uint32_t value, uint8_t *buffer, size_t length)
Write Unsigned 32-Bit Integer to Buffer.
static T readInt(const std::vector< uint8_t > &buf)
Read integer value from a buffer.
PSIDLen(const uint8_t psid_len)
Constructor.
Utility class for option data types.
InvalidDataType(const char *file, size_t line, const char *what)
PSIDLen()
Default constructor.
std::pair< PrefixLen, asiolink::IOAddress > PrefixTuple
Defines a pair of prefix length / value.
Parameters being used to make up an option definition.
uint16_t asUint16() const
Returns PSID value as a number.
Exception to be thrown when invalid type specified as template parameter.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
const OptionDataType * records
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
uint8_t asUint8() const
Returns prefix length as uint8_t value.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
OptionDataType
Data types of DHCP option fields.
uint8_t * writeUint16(uint16_t value, void *buffer, size_t length)
Write Unsigned 16-Bit Integer to Buffer.
uint8_t asUint8() const
Returns PSID length as uint8_t value.
PSID(const uint16_t psid)
Constructor.
PSID()
Default constructor.
uint32_t readUint32(const uint8_t *buffer, size_t length)
Read Unsigned 32-Bit Integer from Buffer.
LengthFieldType
Size of the length field in the tuple.
std::pair< PSIDLen, PSID > PSIDTuple
Defines a pair of PSID length / value.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
uint16_t readUint16(const void *buffer, size_t length)
Read Unsigned 16-Bit Integer from Buffer.
A wrapper interface for the ASIO library.
Represents a single instance of the opaque data preceded by length.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
PrefixLen()
Default constructor.
Exception to be thrown when cast to the data type was unsuccessful.
Trait class for data types supported in DHCP option definitions.
The IOAddress class represents an IP addresses (version agnostic)
unsigned int asUnsigned() const
Returns PSID length as unsigned int.
const struct OptionDefParams * optionDefParams
Encapsulates prefix length.
static void writeInt(const T value, std::vector< uint8_t > &buf)
Append integer or unsigned integer value to a buffer.
BadDataTypeCast(const char *file, size_t line, const char *what)
unsigned int asUnsigned() const
Returns prefix length as unsigned int.