X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2F80221Bundle%2FTLVPacket.hh;h=f2fdc36895a5ef62cb55b7bd73fc029838978668;hb=4891cce7dda76b60f270edfdba16b63d6756c4b0;hp=8f9398b59abb687bbbf6f0916d33166b9341acb2;hpb=32be66071113df31a085821e31414eeb776022fa;p=senf.git diff --git a/Packets/80221Bundle/TLVPacket.hh b/Packets/80221Bundle/TLVPacket.hh index 8f9398b..f2fdc36 100644 --- a/Packets/80221Bundle/TLVPacket.hh +++ b/Packets/80221Bundle/TLVPacket.hh @@ -35,19 +35,12 @@ namespace senf { - /** \brief xxx - - \todo document me - \todo add usefull exceptions strings - - */ - struct UnsuportedTLVPacketException : public senf::Exception - { UnsuportedTLVPacketException() - : senf::Exception("length of length can be max. 4 bytes. Sorry."){} }; - - /** \brief xxx - \todo document me - */ + + struct TLVLengthException : public senf::Exception + { TLVLengthException() + : senf::Exception("TLVLengthException"){} }; + + class DynamicTLVLengthParser : public detail::packet::IntParserOps, public PacketParserBase @@ -67,60 +60,64 @@ namespace senf { size_type bytes() const; void init() const; - private: - typedef FlagParser < 0 > ExtendedLengthFlagParser; - typedef UIntFieldParser < 1, 8 > FixedLengthParser; - - ExtendedLengthFlagParser extended_length_flag() const { - return parse( 0 ); - } +# include SENF_PARSER() + SENF_PARSER_PRIVATE_BITFIELD ( extended_length_flag, 1, bool ); + SENF_PARSER_PRIVATE_BITFIELD ( fixed_length_field, 7, unsigned ); - FixedLengthParser fixed_length_field() const { - return parse( 0 ); - } - void resize(size_type size); + void shrink(); }; - /** \brief parse TLVPacket Packet - - \todo document me - - \see TLVPacketType - */ - template - struct TLVPacketParser : public PacketParserBase + + class BaseTLVPacketParser : public PacketParserBase { # include SENF_PARSER() + SENF_PARSER_FIELD ( type, UInt8Parser ); + SENF_PARSER_FIELD_RO ( length, DynamicTLVLengthParser ); + SENF_PARSER_FINALIZE ( BaseTLVPacketParser ); - SENF_PARSER_FIELD( type, TypeParser ); - SENF_PARSER_FIELD( length, LengthParser ); + void maxLengthValue(DynamicTLVLengthParser::value_type v) const; + void shrinkLength() { length_().shrink(); }; - SENF_PARSER_FINALIZE(TLVPacketParser); + protected: + size_type length_bytes() const { return length_().bytes(); }; + void length(DynamicTLVLengthParser::value_type &v) { length_() = v; }; }; - - /** \brief generic TLV Packet type + + + struct GenericTLVPacketParser : public BaseTLVPacketParser + { +# include SENF_PARSER() + SENF_PARSER_INHERIT( BaseTLVPacketParser ) + SENF_PARSER_FINALIZE( GenericTLVPacketParser ); - \todo document me + SENF_PARSER_INIT() { + maxLengthValue( DynamicTLVLengthParser::max_value); + } + + senf::PacketInterpreterBase::range value() const; - \ingroup protocolbundle_mpegdvb - */ - template - struct TLVPacketType - : public PacketTypeBase + template + void value(ForwardReadableRange const &range); + }; + + struct GenericTLVPacketType + : public PacketTypeBase, + public PacketTypeMixin { - typedef ConcretePacket > packet; - typedef TLVPacketParser parser; + typedef PacketTypeMixin mixin; + typedef ConcretePacket packet; + typedef GenericTLVPacketParser parser; - static optional_range nextPacketRange(packet p); - static size_type initSize(); + using mixin::nextPacketRange; + using mixin::init; + using mixin::initSize; static void finalize(packet p); - static void dump(packet p, std::ostream & os); }; - typedef ConcretePacket > MIHInfoElement; + typedef ConcretePacket GenericTLVPacket; }