2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief TLVParser inline non-template implementation */
17 //#include "TLVParser.ih"
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // MIHFIdTLVParser::binaryNAIDecoder
27 prefix_ senf::MIHFIdTLVParser::binaryNAIDecoder::binaryNAIDecoder()
28 : readNextByte_( true)
31 prefix_ bool senf::MIHFIdTLVParser::binaryNAIDecoder::operator()(boost::uint8_t v)
33 readNextByte_ = readNextByte_ ? false : true;
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 prefix_ senf::PacketParserBase::data_iterator senf::MIHFIdTLVParser::valueBegin()
43 return i( idValue_offset());
46 prefix_ senf::PacketParserBase::data_iterator senf::MIHFIdTLVParser::valueEnd()
49 return i( idValue_offset() + idLength());
52 prefix_ std::string senf::MIHFIdTLVParser::valueAsString()
55 return std::string( valueBegin(), valueEnd());
58 prefix_ senf::MACAddress senf::MIHFIdTLVParser::valueAsMACAddress()
61 if (idLength() != 6*2) throw make_WrapException(std::bad_cast())
62 << " length of MIHF_ID does not match for a MAC address (" << idLength() << ")";
63 return MACAddress::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
66 prefix_ senf::INet4Address senf::MIHFIdTLVParser::valueAsINet4Address()
69 if (idLength() != 4*2) throw make_WrapException(std::bad_cast())
70 << " length of MIHF_ID does not match for an INet4 address (" << idLength() << ")";
71 return INet4Address::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
74 prefix_ senf::INet6Address senf::MIHFIdTLVParser::valueAsINet6Address()
77 if (idLength() != 16*2) throw make_WrapException(std::bad_cast())
78 << " length of MIHF_ID does not match for an INet6 address (" << idLength() << ")";
79 return INet6Address::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
82 prefix_ senf::EUI64 senf::MIHFIdTLVParser::valueAsEUI64()
85 if (idLength() != 8*2) throw make_WrapException(std::bad_cast())
86 << " length of MIHF_ID does not match for an EUI64 address (" << idLength() << ")";
87 return EUI64::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
90 prefix_ bool senf::MIHFIdTLVParser::valueEquals( std::string const &id)
93 return id == valueAsString();
96 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::MACAddress const & addr)
99 return idLength()==12 && addr==valueAsMACAddress();
102 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::INet4Address const & addr)
105 return idLength()==8 && addr==valueAsINet4Address();
108 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::INet6Address const & addr)
111 return idLength()==32 && addr==valueAsINet6Address();
114 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::EUI64 const & addr)
117 return idLength()==16 && addr==valueAsEUI64();
120 prefix_ bool senf::MIHFIdTLVParser::valueEquals( MIHFId const & id)
123 return boost::apply_visitor( ValueEqualsVisitor(*this), id);
126 //-/////////////////////////////////////////////////////////////////////////////////////////////////
133 // c-file-style: "senf"
134 // indent-tabs-mode: nil
135 // ispell-local-dictionary: "american"
136 // compile-command: "scons -u test"
137 // comment-column: 40