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 */
27 #define HH_TLVPacket_ 1
31 #include "../../Packets/Packets.hh"
33 //#include "TLVPacket.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
41 \todo add usefull exceptions strings
44 struct UnsuportedTLVPacketException : public std::exception
46 virtual char const * what() const throw() {
47 return "length of length can be max. 4 bytes. Sorry.";
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;
74 typedef FlagParser < 0 > ExtendedLengthFlagParser;
75 typedef UIntFieldParser < 1, 8 > FixedLengthParser;
77 ExtendedLengthFlagParser extended_length_flag() const {
78 return parse<ExtendedLengthFlagParser>( 0 );
81 FixedLengthParser fixed_length_field() const {
82 return parse<FixedLengthParser>( 0 );
85 void resize(size_type size);
88 /** \brief parse TLVPacket Packet
94 template <class TypeParser, class LengthParser>
95 struct TLVPacketParser : public PacketParserBase
97 # include SENF_PARSER()
99 SENF_PARSER_FIELD( type, TypeParser );
100 SENF_PARSER_FIELD( length, LengthParser );
102 SENF_PARSER_FINALIZE(TLVPacketParser);
105 /** \brief generic TLV Packet type
109 \ingroup protocolbundle_mpegdvb
111 template <class TypeParser, class LengthParser>
113 : public PacketTypeBase
115 typedef ConcretePacket<TLVPacketType<TypeParser, LengthParser> > packet;
116 typedef TLVPacketParser<TypeParser, LengthParser> parser;
118 static optional_range nextPacketRange(packet p);
119 static size_type initSize();
121 static void finalize(packet p);
123 static void dump(packet p, std::ostream & os);
126 typedef ConcretePacket<TLVPacketType<UInt32Parser, DynamicTLVLengthParser> > MIHInfoElement;
130 ///////////////////////////////hh.e////////////////////////////////////////
131 //#include "TLVPacket.cci"
132 #include "TLVPacket.ct"
133 //#include "TLVPacket.cti"
140 // c-file-style: "senf"
141 // indent-tabs-mode: nil
142 // ispell-local-dictionary: "american"
143 // compile-command: "scons -u test"
144 // comment-column: 40