blob: 0b9d6d88985abefd65d4c3893ffedf5cf2b0232b [file] [log] [blame]
shockjiange9c1ab92014-07-21 12:02:52 -07001/*
2 * RR.cpp
3 *
4 * Created on: 18 Jul, 2014
5 * Author: shock
6 */
7
8#include "RR.h"
9
10namespace ndn {
11
12RR::RR()
13: id (0Lu)
14, m_rrData("ex.com")
15{
16 // TODO Auto-generated constructor stub
17
18}
19
20RR::~RR() {
21 // TODO Auto-generated destructor stub
22}
23
24template<bool T>
25size_t
26RR::wireEncode(EncodingImpl<T> & block) const
27{
28 size_t totalLength = 0;
29 string msg = this->getRrdata();
30 totalLength += prependByteArrayBlock(block,
31 tlv::ndns::RRData,
32 reinterpret_cast<const uint8_t*>(msg.c_str()),
33 msg.size()
34 );
35
36 return totalLength;
37}
38
39const Block&
40RR::wireEncode() const
41{
42 if (m_wire.hasWire())
43 return m_wire;
44 EncodingEstimator estimator;
45 size_t estimatedSize = wireEncode(estimator);
46 EncodingBuffer buffer(estimatedSize, 0);
47 wireEncode(buffer);
48 m_wire = buffer.block();
49 return m_wire;
50}
51
52void
53RR::wireDecode(const Block& wire)
54{
55 if (!wire.hasWire()) {
56 throw Tlv::Error("The supplied block does not contain wire format");
57 }
58
59 if (wire.type() != tlv::ndns::RRData)
60 throw Tlv::Error("Unexpected TLV type when decoding Content");
61
62 m_wire = wire;
63 m_wire.parse();
64
65 Block::element_const_iterator it = m_wire.elements_begin();
66
67 if (it != m_wire.elements_end() && it->type() == tlv::ndns::RRData)
68 {
69 m_rrData = string(reinterpret_cast<const char*>(it->value()), it->value_size());
70 it ++;
71 } else {
72 throw Tlv::Error("not the RRData Type");
73 }
74
75}
76
77
78
79} /* namespace ndn */