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 TLVPacket non-inline non-template implementation */
26 #include "TLVPacket.hh"
27 //#include "TLVPacket.ih"
31 #include <senf/Utils/hexdump.hh>
34 ///////////////////////////////cc.p////////////////////////////////////////
36 prefix_ senf::DynamicTLVLengthParser::value_type senf::DynamicTLVLengthParser::value() const
40 return fixed_length_field().value();
42 return parse<UInt8Parser>( 1 ).value();
44 return parse<UInt16Parser>( 1 ).value();
46 return parse<UInt24Parser>( 1 ).value();
48 return parse<UInt32Parser>( 1 ).value();
50 throw(UnsuportedTLVPacketException());
54 prefix_ void senf::DynamicTLVLengthParser::value(value_type const & v)
56 SafePacketParserWrapper<DynamicTLVLengthParser> safeThis (*this);
60 safeThis->fixed_length_field() = v;
63 if (v <= UInt8Parser::max_value) {
66 safeThis->parse<UInt8Parser>(1) = v;
69 if (v <= UInt16Parser::max_value) {
72 safeThis->parse<UInt16Parser>(1) = v;
75 if (v <= UInt24Parser::max_value) {
78 safeThis->parse<UInt24Parser>(1) = v;
81 if (v <= UInt32Parser::max_value) {
84 safeThis->parse<UInt32Parser>(1) = v;
87 throw(UnsuportedTLVPacketException());
90 prefix_ senf::DynamicTLVLengthParser const & senf::DynamicTLVLengthParser::operator= (value_type other)
96 prefix_ senf::DynamicTLVLengthParser::size_type senf::DynamicTLVLengthParser::bytes() const
98 if ( extended_length_flag() )
99 return 1 + fixed_length_field();
104 prefix_ void senf::DynamicTLVLengthParser::init() const
107 extended_length_flag() = 0;
110 prefix_ void senf::DynamicTLVLengthParser::resize(
111 size_type size, SafePacketParserWrapper<DynamicTLVLengthParser> &safeThis)
113 std::cout << "DynamicTLVLengthParser::resize " << unsigned( size) << "\n";
115 safeThis->extended_length_flag() = true;
116 safeThis->fixed_length_field() = size - 1;
118 safeThis->extended_length_flag() = false;
121 size_type current_size (bytes());
122 safe_data_iterator si (data(), i());
124 if (current_size > size)
125 data().erase( si, boost::next(si, current_size-size));
127 data().insert( si, size-current_size, 0);
130 prefix_ void senf::GenericTLVPacketType::dump(packet p, std::ostream & os)
132 boost::io::ios_all_saver ias(os);
133 os << "GenericTLVPacket:\n"
135 << " type: " << unsigned( p->type()) << "\n"
136 << " length: " << unsigned( p->length()) << "\n";
139 //prefix_ void senf::GenericTLVPacketType::finalize(packet p)
142 // PacketData::size_type size = p.next().data().size();
143 // if ( size > DynamicTLVLengthParser::max_value )
144 // throw(UnsuportedTLVPacketException());
145 // p->length() = size;
147 // catch (InvalidPacketChainException & ex) {
153 //template <class TypeParser, class LengthParser>
154 //prefix_ senf::PacketInterpreterBase::optional_range
155 //senf::TLVPacketType<TypeParser, LengthParser>::nextPacketRange(packet p)
157 // if (p.data().size() < 5)
158 // return no_range();
160 // boost::next(p.data().begin(), 4 + senf::bytes(p->length()) ),
165 ///////////////////////////////cc.e////////////////////////////////////////
172 // c-file-style: "senf"
173 // indent-tabs-mode: nil
174 // ispell-local-dictionary: "american"
175 // compile-command: "scons -u test"
176 // comment-column: 40