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 Parse_TLVPacketLength
55 : public detail::packet::ParseIntOps<Parse_TLVPacketLength, boost::uint32_t>,
56 public PacketParserBase
59 Parse_TLVPacketLength(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 Parse_TLVPacketLength const & operator= (value_type other);
71 size_type bytes() const;
76 typedef Parse_Flag < 0 > Parse_extended_length_flag;
77 typedef Parse_UIntField < 1, 8 > Parse_fixed_length;
79 Parse_extended_length_flag extended_length_flag() const {
80 return parse<Parse_extended_length_flag>( 0 );
83 Parse_fixed_length fixed_length_field() const {
84 return parse<Parse_fixed_length>( 0 );
87 void resize(size_type size);
90 /** \brief parse TLVPacket Packet
96 template <class LengthParser>
97 struct Parse_TLVPacket : public PacketParserBase
99 # include SENF_PARSER()
101 SENF_PARSER_FIELD( type, Parse_UInt32 );
102 SENF_PARSER_FIELD( length, LengthParser );
104 SENF_PARSER_FINALIZE(Parse_TLVPacket);
107 /** \brief generic TLV Packet type
111 \ingroup protocolbundle_mpegdvb
113 template <class LengthParser>
115 : public PacketTypeBase
117 typedef ConcretePacket<TLVPacketType<LengthParser> > packet;
118 typedef Parse_TLVPacket<LengthParser> parser;
120 static optional_range nextPacketRange(packet p);
121 static size_type initSize();
123 static void finalize(packet p);
125 static void dump(packet p, std::ostream & os);
128 typedef TLVPacketType<Parse_TLVPacketLength>::packet TLVPacket;
130 typedef TLVPacketType<Parse_UInt8>::packet TLVFix8Packet;
131 typedef TLVPacketType<Parse_UInt16>::packet TLVFix16Packet;
132 typedef TLVPacketType<Parse_UInt24>::packet TLVFix24Packet;
133 typedef TLVPacketType<Parse_UInt32>::packet TLVFix32Packet;
137 ///////////////////////////////hh.e////////////////////////////////////////
138 //#include "TLVPacket.cci"
139 #include "TLVPacket.ct"
140 //#include "TLVPacket.cti"
147 // c-file-style: "senf"
148 // indent-tabs-mode: nil
149 // ispell-local-dictionary: "american"
150 // compile-command: "scons -u test"
151 // comment-column: 40