From 1ac7b8b8391264a4ca80f076761c51bb271af60a Mon Sep 17 00:00:00 2001 From: tho <tho@wiback.org> Date: Fri, 9 Jan 2009 14:57:23 +0000 Subject: [PATCH] added MIHPacketType::finalize --- Packets/80221Bundle/MIHPacket.cc | 7 +++++++ Packets/80221Bundle/MIHPacket.hh | 4 +++- Packets/80221Bundle/TLVPacket.cc | 13 ++++++------- Packets/80221Bundle/TLVPacket.hh | 12 +++++++++--- Packets/80221Bundle/TLVPacket.test.cc | 4 ++-- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Packets/80221Bundle/MIHPacket.cc b/Packets/80221Bundle/MIHPacket.cc index 9b2d89920..ce0e08606 100644 --- a/Packets/80221Bundle/MIHPacket.cc +++ b/Packets/80221Bundle/MIHPacket.cc @@ -53,6 +53,13 @@ prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os) } +prefix_ void senf::MIHPacketType::finalize(packet p) +{ + p->source_length() << senf::bytes( p->source_mihf_id()); + p->destination_length() << senf::bytes( p->destination_mihf_id()); + p->payloadLength_() << p.size() - 8; +} + #undef prefix_ diff --git a/Packets/80221Bundle/MIHPacket.hh b/Packets/80221Bundle/MIHPacket.hh index b84bbe9a6..2c1da37ae 100644 --- a/Packets/80221Bundle/MIHPacket.hh +++ b/Packets/80221Bundle/MIHPacket.hh @@ -80,6 +80,8 @@ namespace senf { source_type() = 1; destination_type() = 2; } + + friend class MIHPacketType; }; @@ -96,7 +98,7 @@ namespace senf { using mixin::initSize; static void dump(packet p, std::ostream &os); -// static void finalize(packet p); + static void finalize(packet p); }; typedef ConcretePacket<MIHPacketType> MIHPacket; diff --git a/Packets/80221Bundle/TLVPacket.cc b/Packets/80221Bundle/TLVPacket.cc index 5c7c0dafe..f79d84b58 100644 --- a/Packets/80221Bundle/TLVPacket.cc +++ b/Packets/80221Bundle/TLVPacket.cc @@ -127,25 +127,24 @@ prefix_ void senf::DynamicTLVLengthParser::shrink() } -prefix_ void senf::BaseTLVPacketParser:: maxLengthValue(DynamicTLVLengthParser::value_type v) - const +prefix_ void senf::DynamicTLVLengthParser:: maxValue(DynamicTLVLengthParser::value_type v) { if (v <= 127) return; - size_type b = senf::bytes( length_()); + size_type b = bytes(); if (v <= UInt8Parser::max_value) { - if (b < 2) length_().resize(2); + if (b < 2) resize(2); return; } if (v <= UInt16Parser::max_value) { - if (b < 3) length_().resize(3); + if (b < 3) resize(3); return; } if (v <= UInt24Parser::max_value) { - if (b < 4) length_().resize(4); + if (b < 4) resize(4); return; } - if (b < 5) length_().resize(5); + if (b < 5) resize(5); } diff --git a/Packets/80221Bundle/TLVPacket.hh b/Packets/80221Bundle/TLVPacket.hh index f2fdc3689..057f06f6e 100644 --- a/Packets/80221Bundle/TLVPacket.hh +++ b/Packets/80221Bundle/TLVPacket.hh @@ -64,8 +64,10 @@ namespace senf { SENF_PARSER_PRIVATE_BITFIELD ( extended_length_flag, 1, bool ); SENF_PARSER_PRIVATE_BITFIELD ( fixed_length_field, 7, unsigned ); - void resize(size_type size); void shrink(); + void maxValue(DynamicTLVLengthParser::value_type v); + private: + void resize(size_type size); }; @@ -76,8 +78,12 @@ namespace senf { SENF_PARSER_FIELD_RO ( length, DynamicTLVLengthParser ); SENF_PARSER_FINALIZE ( BaseTLVPacketParser ); - void maxLengthValue(DynamicTLVLengthParser::value_type v) const; - void shrinkLength() { length_().shrink(); }; + void maxLengthValue(DynamicTLVLengthParser::value_type v) const { + length_().maxValue(v); + } + void shrinkLength() { + length_().shrink(); + }; protected: size_type length_bytes() const { return length_().bytes(); }; diff --git a/Packets/80221Bundle/TLVPacket.test.cc b/Packets/80221Bundle/TLVPacket.test.cc index 043a93d34..0e46beb06 100644 --- a/Packets/80221Bundle/TLVPacket.test.cc +++ b/Packets/80221Bundle/TLVPacket.test.cc @@ -149,8 +149,8 @@ namespace { struct TestMacAddressTLVPacketParser : public BaseTLVPacketParser { # include SENF_PARSER() - SENF_PARSER_INHERIT ( BaseTLVPacketParser ) - SENF_PARSER_VECTOR ( value, bytes(length), senf::MACAddressParser ) + SENF_PARSER_INHERIT ( BaseTLVPacketParser ); + SENF_PARSER_VECTOR ( value, bytes(length), senf::MACAddressParser ); SENF_PARSER_FINALIZE( TestMacAddressTLVPacketParser ); }; -- GitLab