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 public header */
26 #ifndef HH_SENF_Packets_80221Bundle_TLVPacket_
27 #define HH_SENF_Packets_80221Bundle_TLVPacket_ 1
31 #include "../../Packets/Packets.hh"
33 //#include "TLVPacket.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
41 \todo add usefull exceptions strings
43 \ingroup protocolbundle_80221
45 struct UnsuportedTLVPacketException : public senf::Exception
46 { UnsuportedTLVPacketException()
47 : senf::Exception("length of length can be max. 4 bytes. Sorry."){} };
52 \ingroup protocolbundle_80221
54 class DynamicTLVLengthParser
55 : public detail::packet::IntParserOps<DynamicTLVLengthParser, boost::uint32_t>,
56 public PacketParserBase
59 DynamicTLVLengthParser(data_iterator i, state_type s) : PacketParserBase(i,s) {}
61 typedef boost::uint32_t value_type;
62 static const size_type init_bytes = 1;
63 static value_type const min_value = 0;
64 static value_type const max_value = 4294967295u;
66 value_type value() const;
67 void value(value_type const & v);
69 DynamicTLVLengthParser const & operator= (value_type other);
70 size_type bytes() const;
73 # include SENF_PARSER()
75 SENF_PARSER_PRIVATE_BITFIELD ( extended_length_flag, 1, bool );
76 SENF_PARSER_PRIVATE_BITFIELD ( fixed_length_field, 7, unsigned );
80 // typedef FlagParser < 0 > ExtendedLengthFlagParser;
81 // typedef UIntFieldParser < 1, 8 > FixedLengthParser;
83 // ExtendedLengthFlagParser extended_length_flag() const {
84 // return parse<ExtendedLengthFlagParser>( 0 );
87 // FixedLengthParser fixed_length_field() const {
88 // return parse<FixedLengthParser>( 0 );
91 void resize(size_type size, SafePacketParserWrapper<DynamicTLVLengthParser> &safeThis);
94 /** \brief parse TLVPacket Packet
100 \ingroup protocolbundle_80221
102 struct GenericTLVPacketParser : public PacketParserBase
104 # include SENF_PARSER()
106 SENF_PARSER_FIELD ( type, UInt8Parser );
107 SENF_PARSER_FIELD_RO ( length, DynamicTLVLengthParser );
108 SENF_PARSER_VECTOR ( value, bytes(length), UInt8Parser );
110 SENF_PARSER_FINALIZE( GenericTLVPacketParser );
113 /** \brief generic TLV Packet type
117 \ingroup protocolbundle_80221
119 struct GenericTLVPacketType
120 : public PacketTypeBase,
121 public PacketTypeMixin<GenericTLVPacketType>
123 typedef PacketTypeMixin<GenericTLVPacketType> mixin;
124 typedef ConcretePacket<GenericTLVPacketType> packet;
125 typedef GenericTLVPacketParser parser;
127 // static optional_range nextPacketRange(packet p);
128 using mixin::nextPacketRange;
130 using mixin::initSize;
132 // static void finalize(packet p);
133 static void dump(packet p, std::ostream & os);
136 typedef ConcretePacket<GenericTLVPacketType> GenericTLVPacket;
140 ///////////////////////////////hh.e////////////////////////////////////////
141 //#include "TLVPacket.cci"
142 //#include "TLVPacket.ct"
143 //#include "TLVPacket.cti"
150 // c-file-style: "senf"
151 // indent-tabs-mode: nil
152 // ispell-local-dictionary: "american"
153 // compile-command: "scons -u test"
154 // comment-column: 40