Kea  1.9.9-git
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 
21 using namespace std;
22 using namespace isc::util;
23 using isc::dns::RRType;
24 
25 namespace isc {
26 namespace dns {
27 
28 RRType::RRType(const std::string& type_str) {
29  uint16_t typecode;
30  if (!RRParamRegistry::getRegistry().textToTypeCode(type_str, typecode)) {
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 
44 const string
45 RRType::toText() const {
46  return (RRParamRegistry::getRegistry().codeToTypeText(typecode_));
47 }
48 
49 void
50 RRType::toWire(OutputBuffer& buffer) const {
51  buffer.writeUint16(typecode_);
52 }
53 
54 void
55 RRType::toWire(AbstractMessageRenderer& renderer) const {
56  renderer.writeUint16(typecode_);
57 }
58 
59 ostream&
60 operator<<(ostream& os, const RRType& rrtype) {
61  os << rrtype.toText();
62  return (os);
63 }
64 }
65 }
size_t getLength() const
Return the length of the data stored in the buffer.
Definition: buffer.h:100
A standard DNS module exception that is thrown if an RRType object is being constructed from a incomp...
Definition: rrtype.h:54
STL namespace.
ostream & operator<<(ostream &os, const RRType &rrtype)
Insert the RRType as a string into stream.
Definition: rrtype.cc:60
const std::string toText() const
Convert the RRType to a string.
Definition: rrtype.cc:45
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the internal buffer in network byte order...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: edns.h:19
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
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
Defines the logger used by the top-level component of kea-dhcp-ddns.
size_t getPosition() const
Return the current read position.
Definition: buffer.h:102
The RRType class encapsulates DNS resource record types.
Definition: rrtype.h:106
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
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81
A standard DNS module exception that is thrown if an RRType object is being constructed from an unrec...
Definition: rrtype.h:44