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)
57 throw(UnsuportedTLVPacketException());
59 SafePacketParserWrapper<DynamicTLVLengthParser> safeThis (*this);
63 safeThis->extended_length_flag() = false;
65 safeThis->fixed_length_field() = v;
71 safeThis->extended_length_flag() = true;
72 safeThis->fixed_length_field() = 1;
74 safeThis->parse<UInt8Parser>(1) = v;
80 safeThis->extended_length_flag() = true;
81 safeThis->fixed_length_field() = 2;
83 safeThis->parse<UInt16Parser>(1) = v;
89 safeThis->extended_length_flag() = true;
90 safeThis->fixed_length_field() = 3;
92 safeThis->parse<UInt24Parser>(1) = v;
95 if (v <= 4294967295u) {
98 safeThis->extended_length_flag() = true;
99 safeThis->fixed_length_field() = 4;
101 safeThis->parse<UInt32Parser>(1) = v;
106 prefix_ senf::DynamicTLVLengthParser const & senf::DynamicTLVLengthParser::operator= (value_type other)
112 prefix_ senf::DynamicTLVLengthParser::size_type senf::DynamicTLVLengthParser::bytes() const
114 if ( extended_length_flag() )
115 return 1 + fixed_length_field();
120 prefix_ void senf::DynamicTLVLengthParser::init() const
123 extended_length_flag() = 0;
126 prefix_ void senf::DynamicTLVLengthParser::resize(size_type size)
128 size_type current_size (bytes());
129 safe_data_iterator si (data(), i());
131 if (current_size > size)
132 data().erase( si, boost::next(si, current_size-size));
134 data().insert( si, size-current_size, 0);
138 ///////////////////////////////cc.e////////////////////////////////////////
145 // c-file-style: "senf"
146 // indent-tabs-mode: nil
147 // ispell-local-dictionary: "american"
148 // compile-command: "scons -u test"
149 // comment-column: 40