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 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 TLVPacketLengthParser
55 : public detail::packet::IntParserOps<TLVPacketLengthParser, boost::uint32_t>,
56 public PacketParserBase
59 TLVPacketLengthParser(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 TLVPacketLengthParser const & operator= (value_type other);
71 size_type bytes() const;
76 typedef FlagParser < 0 > ExtendedLengthFlagParser;
77 typedef UIntFieldParser < 1, 8 > FixedLengthParser;
79 ExtendedLengthFlagParser extended_length_flag() const {
80 return parse<ExtendedLengthFlagParser>( 0 );
83 FixedLengthParser fixed_length_field() const {
84 return parse<FixedLengthParser>( 0 );
87 void resize(size_type size);
90 /** \brief parse TLVPacket Packet
96 template <class LengthParser>
97 struct TLVPacketParser : public PacketParserBase
99 # include SENF_PARSER()
101 SENF_PARSER_FIELD( type, UInt32Parser );
102 SENF_PARSER_FIELD( length, LengthParser );
104 SENF_PARSER_FINALIZE(TLVPacketParser);
107 /** \brief generic TLV Packet type
111 \ingroup protocolbundle_mpegdvb
113 template <class LengthParser>
115 : public PacketTypeBase
118 typedef ConcretePacket<TLVPacketType<LengthParser> > packet;
119 typedef TLVPacketParser<LengthParser> parser;
121 static optional_range nextPacketRange(packet p);
122 static size_type initSize();
124 static void finalize(packet p);
126 static void dump(packet p, std::ostream & os);
129 typedef TLVPacketType<TLVPacketLengthParser>::packet TLVPacket;
131 typedef ConcretePacket<TLVPacketType<UInt8Parser> > TLVFix8Packet;
132 typedef ConcretePacket<TLVPacketType<UInt16Parser> > TLVFix16Packet;
133 typedef ConcretePacket<TLVPacketType<UInt24Parser> > TLVFix24Packet;
134 typedef ConcretePacket<TLVPacketType<UInt32Parser> > TLVFix32Packet;
138 ///////////////////////////////hh.e////////////////////////////////////////
139 //#include "TLVPacket.cci"
140 #include "TLVPacket.ct"
141 //#include "TLVPacket.cti"
148 // c-file-style: "senf"
149 // indent-tabs-mode: nil
150 // ispell-local-dictionary: "american"
151 // compile-command: "scons -u test"
152 // comment-column: 40