1 // $Id: SNDUPacket.hh 423 2007-08-31 22:05:37Z g0dil $
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 SNDUPacket public header */
27 #define HH_TLVPacket_ 1
31 #include "../../Packets/PacketType.hh"
32 #include "../../Packets/ParseInt.hh"
33 #include "../../Packets/PacketParser.hh"
35 //#include "TLVPacket.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
41 struct UnsuportedTLVPacketException : public std::exception
43 virtual char const * what() const throw() {
44 return "length of length can be max. 4 bytes. Sorry.";
48 struct Parse_TLVPacketLength
49 : public detail::packet::ParseIntOps<Parse_TLVPacketLength, boost::uint32_t>,
50 public PacketParserBase
54 SENF_PACKET_PARSER_NO_INIT(Parse_TLVPacketLength);
56 typedef Parse_Flag < 0 > Parse_extended_length_flag;
57 typedef Parse_UIntField < 1, 8 > Parse_fixed_length;
59 SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
60 ((OverlayField)( extended_length_flag, Parse_extended_length_flag ))
61 ((Field )( fixed_length_field, Parse_fixed_length ))
66 typedef boost::uint32_t value_type;
68 value_type value() const {
71 return fixed_length_field().value();
73 return parse<Parse_UInt8>( 1 ).value();
75 return parse<Parse_UInt16>( 1 ).value();
77 return parse<Parse_UInt24>( 1 ).value();
79 return parse<Parse_UInt32>( 1 ).value();
81 throw(UnsuportedTLVPacketException());
85 size_type bytes() const {
86 if ( extended_length_flag() )
87 return 1 + fixed_length_field();
94 extended_length_flag() = 0;
99 /** \brief parse TLVPacket Packet
105 struct Parse_TLVPacket : public PacketParserBase
109 SENF_PACKET_PARSER_INIT(Parse_TLVPacket);
111 SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
112 ((Field)( type, Parse_UInt32 ))
113 ((Field)( length, Parse_TLVPacketLength ))
118 // Parse_UInt32 type() const {
119 // return parse<Parse_UInt32>( 0 );
122 // Parse_TLVPacketLength length() const {
123 // return parse<Parse_TLVPacketLength>( 4 );
126 PacketParserBase::size_type bytes() const;
128 static const size_type init_bytes = 4+1; // 4 bytes type + 1 byte length
132 /** \brief TLV Packet
134 \par Packet type (typedef):
140 \ingroup protocolbundle_mpegdvb
143 : public PacketTypeBase,
144 public PacketTypeMixin<TLVPacketType>
146 typedef PacketTypeMixin<TLVPacketType> mixin;
147 typedef ConcretePacket<TLVPacketType> packet;
148 typedef Parse_TLVPacket parser;
150 using mixin::nextPacketRange;
152 using mixin::initSize;
154 static void dump(packet p, std::ostream & os);
156 // static PacketParserBase::size_type initSize();
157 // static PacketParserBase::size_type initHeadSize();
160 typedef TLVPacketType::packet TLVPacket;
165 ///////////////////////////////hh.e////////////////////////////////////////
166 //#include "TLVPacket.cci"
167 //#include "TLVPacket.ct"
168 //#include "TLVPacket.cti"
175 // c-file-style: "senf"
176 // indent-tabs-mode: nil
177 // ispell-local-dictionary: "american"
178 // compile-command: "scons -u test"
179 // comment-column: 40