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_MPEGDVBBundle_TLVPacket_
27 #define HH_SENF_Packets_MPEGDVBBundle_TLVPacket_ 1
31 #include "../../Packets/Packets.hh"
33 //#include "TLVPacket.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
41 \todo add usefull exceptions strings
44 struct UnsuportedTLVPacketException : public senf::Exception
45 { UnsuportedTLVPacketException()
46 : senf::Exception("length of length can be max. 4 bytes. Sorry."){} };
51 class DynamicTLVLengthParser
52 : public detail::packet::IntParserOps<DynamicTLVLengthParser, boost::uint32_t>,
53 public PacketParserBase
56 DynamicTLVLengthParser(data_iterator i, state_type s) : PacketParserBase(i,s) {}
58 typedef boost::uint32_t value_type;
59 static const size_type init_bytes = 1;
60 static value_type const min_value = 0;
61 static value_type const max_value = 4294967295u;
63 value_type value() const;
64 void value(value_type const & v);
66 DynamicTLVLengthParser const & operator= (value_type other);
67 size_type bytes() const;
71 typedef FlagParser < 0 > ExtendedLengthFlagParser;
72 typedef UIntFieldParser < 1, 8 > FixedLengthParser;
74 ExtendedLengthFlagParser extended_length_flag() const {
75 return parse<ExtendedLengthFlagParser>( 0 );
78 FixedLengthParser fixed_length_field() const {
79 return parse<FixedLengthParser>( 0 );
82 void resize(size_type size);
85 /** \brief parse TLVPacket Packet
91 template <class TypeParser, class LengthParser>
92 struct TLVPacketParser : public PacketParserBase
94 # include SENF_PARSER()
96 SENF_PARSER_FIELD( type, TypeParser );
97 SENF_PARSER_FIELD( length, LengthParser );
99 SENF_PARSER_FINALIZE(TLVPacketParser);
102 /** \brief generic TLV Packet type
106 \ingroup protocolbundle_mpegdvb
108 template <class TypeParser, class LengthParser>
110 : public PacketTypeBase
112 typedef ConcretePacket<TLVPacketType<TypeParser, LengthParser> > packet;
113 typedef TLVPacketParser<TypeParser, LengthParser> parser;
115 static optional_range nextPacketRange(packet p);
116 static size_type initSize();
118 static void finalize(packet p);
120 static void dump(packet p, std::ostream & os);
123 typedef ConcretePacket<TLVPacketType<UInt32Parser, DynamicTLVLengthParser> > MIHInfoElement;
127 ///////////////////////////////hh.e////////////////////////////////////////
128 //#include "TLVPacket.cci"
129 #include "TLVPacket.ct"
130 //#include "TLVPacket.cti"
137 // c-file-style: "senf"
138 // indent-tabs-mode: nil
139 // ispell-local-dictionary: "american"
140 // compile-command: "scons -u test"
141 // comment-column: 40