| Kea 3.0.2-git

rrtype.cc
Go to the documentation of this file.
1// Copyright (C) 2010-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#include <config.h>
8
9#include <exceptions/exceptions.h>
10#include <dns/messagerenderer.h>
11#include <dns/rrparamregistry.h>
12#include <dns/rrtype.h>
13#include <util/buffer.h>
14
15#include <stdint.h>
16#include <string>
17#include <ostream>
18
19 using namespace isc::util;
20 using isc::dns::RRType;
21
22 using namespace std;
23
24 namespace isc {
25 namespace dns {
26
27 RRType::RRType(const std::string& type_str) {
28 uint16_t typecode;
29 if (!RRParamRegistry::getRegistry().textToTypeCode(type_str, typecode)) {
30 isc_throw(InvalidRRType,
31 "Unrecognized RR type string: " + type_str);
32 }
33 typecode_ = typecode;
34}
35
36 RRType::RRType(InputBuffer& buffer) {
37 if (buffer.getLength() - buffer.getPosition() < sizeof(uint16_t)) {
38 isc_throw(IncompleteRRType, "incomplete wire-format RR type");
39 }
40 typecode_ = buffer.readUint16();
41}
42
43 const string
44 RRType::toText() const {
45 return (RRParamRegistry::getRegistry().codeToTypeText(typecode_));
46}
47
48 void
49 RRType::toWire(OutputBuffer& buffer) const {
50 buffer.writeUint16(typecode_);
51}
52
53 void
54 RRType::toWire(AbstractMessageRenderer& renderer) const {
55 renderer.writeUint16(typecode_);
56}
57
58ostream&
59 operator<<(ostream& os, const RRType& rrtype) {
60 os << rrtype.toText();
61 return (os);
62}
63}
64}
buffer.h
isc::dns::AbstractMessageRenderer
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
Definition messagerenderer.h:69
isc::dns::AbstractMessageRenderer::writeUint16
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the internal buffer in network byte order.
Definition messagerenderer.h:277
isc::dns::IncompleteRRType
A standard DNS module exception that is thrown if an RRType object is being constructed from a incomp...
Definition rrtype.h:44
isc::dns::InvalidRRType
A standard DNS module exception that is thrown if an RRType object is being constructed from an unrec...
Definition rrtype.h:34
isc::dns::RRParamRegistry::getRegistry
static RRParamRegistry & getRegistry()
Return the singleton instance of RRParamRegistry.
Definition rrparamregistry.cc:318
isc::dns::RRType
The RRType class encapsulates DNS resource record types.
Definition rrtype.h:96
isc::dns::RRType::RRType
RRType(uint16_t typecode)
Constructor from an integer type code.
Definition rrtype.h:107
isc::dns::RRType::toWire
void toWire(AbstractMessageRenderer &renderer) const
Render the RRType in the wire format.
Definition rrtype.cc:54
isc::dns::RRType::toText
const std::string toText() const
Convert the RRType to a string.
Definition rrtype.cc:44
isc::util::InputBuffer
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition buffer.h:81
isc::util::InputBuffer::getPosition
size_t getPosition() const
Return the current read position.
Definition buffer.h:101
isc::util::InputBuffer::getLength
size_t getLength() const
Return the length of the data stored in the buffer.
Definition buffer.h:96
isc::util::InputBuffer::readUint16
uint16_t readUint16()
Read an unsigned 16-bit integer in network byte order from the buffer, and return it.
Definition buffer.h:166
isc::util::OutputBuffer
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:346
isc::util::OutputBuffer::writeUint16
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order.
Definition buffer.h:501
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
messagerenderer.h
isc::dns
Definition char_string.cc:26
isc::dns::operator<<
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition edns.cc:163
isc::util
Definition time_utils.cc:43
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
rrparamregistry.h
rrtype.h