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 non-inline non-template implementation */
26 #include "TLVParser.hh"
27 //#include "TLVParser.ih"
31 #include <senf/Utils/hexdump.hh>
34 ///////////////////////////////cc.p////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////
39 prefix_ senf::safe_data_iterator senf::MIHBaseTLVParser::resizeValueField(
40 MIHTLVLengthParser::value_type size)
42 MIHTLVLengthParser::value_type current_length ( length());
45 safe_data_iterator si (data(), boost::next(i(), 1 + length_().bytes() ));
46 if (current_length > size)
47 data().erase( si, boost::next(si, current_length-size));
49 data().insert( si, size-current_length, 0);
54 ///////////////////////////////////////////////////////////////////////////
57 prefix_ senf::MIHTLVLengthParser::value_type senf::MIHTLVLengthParser::value() const
61 return length_field().value();
63 return parse<UInt8Parser>( 1 ).value() + (underflow_flag() ? 0 : 128u);
65 return parse<UInt16Parser>( 1 ).value() + (underflow_flag() ? 0 : 128u);
67 return parse<UInt24Parser>( 1 ).value() + (underflow_flag() ? 0 : 128u);
69 return parse<UInt32Parser>( 1 ).value() + (underflow_flag() ? 0 : 128u);
71 throw( MIHTLVLengthException());
76 prefix_ void senf::MIHTLVLengthParser::value(value_type const & v)
80 if (v > 128) throw( MIHTLVLengthException());
84 if (v > UInt8Parser::max_value + 128) throw( MIHTLVLengthException());
85 parse<UInt8Parser>(1) = v - (v>128 ? 128 : 0);
88 if (v > UInt16Parser::max_value + 128) throw( MIHTLVLengthException());
89 parse<UInt16Parser>(1) = v - (v>128 ? 128 : 0);
92 if (v > UInt24Parser::max_value + 128) throw( MIHTLVLengthException());
93 parse<UInt24Parser>(1) = v - (v>128 ? 128 : 0);
96 parse<UInt32Parser>(1) = v - (v>128 ? 128 : 0);
99 throw( MIHTLVLengthException());
101 underflow_flag() = (v <= 128);
105 prefix_ senf::MIHTLVLengthParser::value_type senf::MIHTLVLengthParser::maxValue()
112 return UInt8Parser::max_value + 128;
114 return UInt16Parser::max_value + 128;
116 return UInt24Parser::max_value + 128;
118 return UInt32Parser::max_value;
120 throw( MIHTLVLengthException());
125 prefix_ senf::MIHTLVLengthParser const & senf::MIHTLVLengthParser::operator= (value_type other)
132 prefix_ void senf::MIHTLVLengthParser::init() const
135 extended_length_flag() = false;
139 prefix_ void senf::MIHTLVLengthParser::finalize()
141 value_type v = value();
142 size_type b = bytes();
144 if (b != 1) resize_(1);
147 if (v <= UInt8Parser::max_value + 128) {
148 if (b != 2) resize_(2);
151 if (v <= UInt16Parser::max_value + 128) {
152 if (b != 3) resize_(3);
155 if (v <= UInt24Parser::max_value + 128 ) {
156 if (b != 4) resize_(4);
159 if (b != 5) resize_(5);
163 prefix_ void senf::MIHTLVLengthParser:: maxValue(MIHTLVLengthParser::value_type v)
167 size_type b = bytes();
168 if (v <= UInt8Parser::max_value + 128) {
169 if (b < 2) resize_(2);
172 if (v <= UInt16Parser::max_value + 128) {
173 if (b < 3) resize_(3);
176 if (v <= UInt24Parser::max_value + 128) {
177 if (b < 4) resize_(4);
180 if (b < 5) resize_(5);
184 prefix_ void senf::MIHTLVLengthParser::resize_(size_type size)
186 value_type v = value();
187 resize(bytes(), size);
189 extended_length_flag() = true;
190 fixed_length_field() = size - 1;
192 extended_length_flag() = false;
198 ///////////////////////////////cc.e////////////////////////////////////////
205 // c-file-style: "senf"
206 // indent-tabs-mode: nil
207 // ispell-local-dictionary: "american"
208 // compile-command: "scons -u test"
209 // comment-column: 40