Kea: rrtype.cc Source File

| Kea 2.2.0

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