4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief TLVParser inline non-template implementation */
26 //#include "TLVParser.ih"
30 #define prefix_ inline
31 //-/////////////////////////////////////////////////////////////////////////////////////////////////
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36 prefix_ senf::MIHTLVLengthParser::size_type senf::MIHTLVLengthParser::bytes() const
38 return 1 + ( length_field()<=128 ? 0 : fixed_length_field());
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 // MIHFIdTLVParser::binaryNAIDecoder
44 prefix_ senf::MIHFIdTLVParser::binaryNAIDecoder::binaryNAIDecoder()
45 : readNextByte_( true)
48 prefix_ bool senf::MIHFIdTLVParser::binaryNAIDecoder::operator()(boost::uint8_t v)
50 readNextByte_ = readNextByte_ ? false : true;
54 //-/////////////////////////////////////////////////////////////////////////////////////////////////
57 prefix_ senf::PacketParserBase::data_iterator senf::MIHFIdTLVParser::valueBegin()
60 return i( idValue_offset());
63 prefix_ senf::PacketParserBase::data_iterator senf::MIHFIdTLVParser::valueEnd()
66 return i( idValue_offset() + idLength());
69 prefix_ std::string senf::MIHFIdTLVParser::valueAsString()
72 return std::string( valueBegin(), valueEnd());
75 prefix_ senf::MACAddress senf::MIHFIdTLVParser::valueAsMACAddress()
78 if (idLength() != 6*2) throw WrapException<std::bad_cast>(std::bad_cast())
79 << "length of MIHF_ID does not match for a MAC address";
80 return MACAddress::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
83 prefix_ senf::INet4Address senf::MIHFIdTLVParser::valueAsINet4Address()
86 if (idLength() != 4*2) throw WrapException<std::bad_cast>(std::bad_cast())
87 << "length of MIHF_ID does not match for a INet4 address";
88 return INet4Address::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
91 prefix_ senf::INet6Address senf::MIHFIdTLVParser::valueAsINet6Address()
94 if (idLength() != 16*2) throw WrapException<std::bad_cast>(std::bad_cast())
95 << "length of MIHF_ID does not match for a INet6 address";
96 return INet6Address::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
99 prefix_ senf::EUI64 senf::MIHFIdTLVParser::valueAsEUI64()
102 if (idLength() != 8*2) throw WrapException<std::bad_cast>(std::bad_cast())
103 << "length of MIHF_ID does not match for a EUI64 address";
104 return EUI64::from_data( getNAIDecodedIterator( valueBegin(), valueEnd()));
107 prefix_ bool senf::MIHFIdTLVParser::valueEquals( std::string const &id)
110 return id == valueAsString();
113 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::MACAddress const & addr)
116 return idLength()==12 && addr==valueAsMACAddress();
119 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::INet4Address const & addr)
122 return idLength()==8 && addr==valueAsINet4Address();
125 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::INet6Address const & addr)
128 return idLength()==32 && addr==valueAsINet6Address();
131 prefix_ bool senf::MIHFIdTLVParser::valueEquals( senf::EUI64 const & addr)
134 return idLength()==16 && addr==valueAsEUI64();
137 prefix_ bool senf::MIHFIdTLVParser::valueEquals( MIHFId const & id)
140 return boost::apply_visitor( ValueEqualsVisitor(*this), id);
144 //-/////////////////////////////////////////////////////////////////////////////////////////////////
147 prefix_ void senf::MIHBaseTLVParser::maxLength(MIHTLVLengthParser::value_type maxl)
150 protect(), length_().capacity(maxl);
153 prefix_ void senf::MIHBaseTLVParser::finalize()
155 protect(), length_().finalize();
159 //-/////////////////////////////////////////////////////////////////////////////////////////////////
166 // c-file-style: "senf"
167 // indent-tabs-mode: nil
168 // ispell-local-dictionary: "american"
169 // compile-command: "scons -u test"
170 // comment-column: 40