4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Thorsten Horstmann <thorsten.horstmann@fokus.fraunhofer.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::Parse_TLVPacketLength::value_type senf::Parse_TLVPacketLength::value() const {
39 return fixed_length_field().value();
41 return parse<Parse_UInt8>( 1 ).value();
43 return parse<Parse_UInt16>( 1 ).value();
45 return parse<Parse_UInt24>( 1 ).value();
47 return parse<Parse_UInt32>( 1 ).value();
49 throw(UnsuportedTLVPacketException());
53 prefix_ void senf::Parse_TLVPacketLength::value(value_type const & v) {
55 throw(UnsuportedTLVPacketException());
58 if (bytes() != 1) resize(1);
59 fixed_length_field() = v;
63 if (bytes() != 2) resize(2);
64 parse<Parse_UInt8>(1) = v;
68 if (bytes() != 3) resize(3);
69 parse<Parse_UInt16>(1) = v;
73 if (bytes() != 4) resize(4);
74 parse<Parse_UInt24>(1) = v;
77 if (v <= 4294967295u) {
78 if (bytes() != 5) resize(5);
79 parse<Parse_UInt32>(1) = v;
84 prefix_ senf::Parse_TLVPacketLength const & senf::Parse_TLVPacketLength::operator= (value_type other) {
89 prefix_ senf::Parse_TLVPacketLength::size_type senf::Parse_TLVPacketLength::bytes() const {
90 if ( extended_length_flag() )
91 return 1 + fixed_length_field();
96 prefix_ void senf::Parse_TLVPacketLength::init() const {
98 extended_length_flag() = 0;
101 prefix_ void senf::Parse_TLVPacketLength::resize(size_type size) {
102 std::cout << "senf::Parse_TLVPacketLength::resize: " << unsigned(size) << "\n";
103 // hexdump(data().begin(), data().end(), std::cout);
105 size_type current_size (bytes());
106 safe_data_iterator si (data(), i());
108 if (current_size > size)
109 data().erase( si, boost::next(si, current_size-size));
111 data().insert( si, size-current_size, 0);
112 Parse_TLVPacketLength(si,state()).init();
116 extended_length_flag() = 1;
117 fixed_length_field() = size-1;
119 extended_length_flag() = 0;
122 // hexdump(data().begin(), data().end(), std::cout);
126 prefix_ void senf::TLVPacketType::dump(packet p, std::ostream & os)
130 << " type: " << unsigned(p->type()) << "\n"
131 << " length: " << unsigned(p->length()) << "\n";
134 prefix_ senf::PacketParserBase::size_type senf::TLVPacketType::initSize()
136 return 5; // 4 bytes type + 1 byte length
139 prefix_ void senf::TLVPacketType::init(packet p)
144 prefix_ void senf::TLVPacketType::finalize(packet p)
146 p->length() = p.next().data().size();
149 prefix_ senf::PacketInterpreterBase::optional_range
150 senf::TLVPacketType::nextPacketRange(packet p)
152 if (p.data().size() < 5)
155 boost::next(p.data().begin(), 4 + senf::bytes(p->length()) ),
160 ///////////////////////////////cc.e////////////////////////////////////////
167 // c-file-style: "senf"
168 // indent-tabs-mode: nil
169 // ispell-local-dictionary: "american"
170 // compile-command: "scons -u test"
171 // comment-column: 40