Skip to content
Snippets Groups Projects
Commit 1ac7b8b8 authored by tho's avatar tho
Browse files

added MIHPacketType::finalize

parent 747786f7
No related branches found
No related tags found
No related merge requests found
...@@ -53,6 +53,13 @@ prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os) ...@@ -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_ #undef prefix_
......
...@@ -80,6 +80,8 @@ namespace senf { ...@@ -80,6 +80,8 @@ namespace senf {
source_type() = 1; source_type() = 1;
destination_type() = 2; destination_type() = 2;
} }
friend class MIHPacketType;
}; };
...@@ -96,7 +98,7 @@ namespace senf { ...@@ -96,7 +98,7 @@ namespace senf {
using mixin::initSize; using mixin::initSize;
static void dump(packet p, std::ostream &os); static void dump(packet p, std::ostream &os);
// static void finalize(packet p); static void finalize(packet p);
}; };
typedef ConcretePacket<MIHPacketType> MIHPacket; typedef ConcretePacket<MIHPacketType> MIHPacket;
......
...@@ -127,25 +127,24 @@ prefix_ void senf::DynamicTLVLengthParser::shrink() ...@@ -127,25 +127,24 @@ prefix_ void senf::DynamicTLVLengthParser::shrink()
} }
prefix_ void senf::BaseTLVPacketParser:: maxLengthValue(DynamicTLVLengthParser::value_type v) prefix_ void senf::DynamicTLVLengthParser:: maxValue(DynamicTLVLengthParser::value_type v)
const
{ {
if (v <= 127) if (v <= 127)
return; return;
size_type b = senf::bytes( length_()); size_type b = bytes();
if (v <= UInt8Parser::max_value) { if (v <= UInt8Parser::max_value) {
if (b < 2) length_().resize(2); if (b < 2) resize(2);
return; return;
} }
if (v <= UInt16Parser::max_value) { if (v <= UInt16Parser::max_value) {
if (b < 3) length_().resize(3); if (b < 3) resize(3);
return; return;
} }
if (v <= UInt24Parser::max_value) { if (v <= UInt24Parser::max_value) {
if (b < 4) length_().resize(4); if (b < 4) resize(4);
return; return;
} }
if (b < 5) length_().resize(5); if (b < 5) resize(5);
} }
......
...@@ -64,8 +64,10 @@ namespace senf { ...@@ -64,8 +64,10 @@ namespace senf {
SENF_PARSER_PRIVATE_BITFIELD ( extended_length_flag, 1, bool ); SENF_PARSER_PRIVATE_BITFIELD ( extended_length_flag, 1, bool );
SENF_PARSER_PRIVATE_BITFIELD ( fixed_length_field, 7, unsigned ); SENF_PARSER_PRIVATE_BITFIELD ( fixed_length_field, 7, unsigned );
void resize(size_type size);
void shrink(); void shrink();
void maxValue(DynamicTLVLengthParser::value_type v);
private:
void resize(size_type size);
}; };
...@@ -76,8 +78,12 @@ namespace senf { ...@@ -76,8 +78,12 @@ namespace senf {
SENF_PARSER_FIELD_RO ( length, DynamicTLVLengthParser ); SENF_PARSER_FIELD_RO ( length, DynamicTLVLengthParser );
SENF_PARSER_FINALIZE ( BaseTLVPacketParser ); SENF_PARSER_FINALIZE ( BaseTLVPacketParser );
void maxLengthValue(DynamicTLVLengthParser::value_type v) const; void maxLengthValue(DynamicTLVLengthParser::value_type v) const {
void shrinkLength() { length_().shrink(); }; length_().maxValue(v);
}
void shrinkLength() {
length_().shrink();
};
protected: protected:
size_type length_bytes() const { return length_().bytes(); }; size_type length_bytes() const { return length_().bytes(); };
......
...@@ -149,8 +149,8 @@ namespace { ...@@ -149,8 +149,8 @@ namespace {
struct TestMacAddressTLVPacketParser : public BaseTLVPacketParser struct TestMacAddressTLVPacketParser : public BaseTLVPacketParser
{ {
# include SENF_PARSER() # include SENF_PARSER()
SENF_PARSER_INHERIT ( BaseTLVPacketParser ) SENF_PARSER_INHERIT ( BaseTLVPacketParser );
SENF_PARSER_VECTOR ( value, bytes(length), senf::MACAddressParser ) SENF_PARSER_VECTOR ( value, bytes(length), senf::MACAddressParser );
SENF_PARSER_FINALIZE( TestMacAddressTLVPacketParser ); SENF_PARSER_FINALIZE( TestMacAddressTLVPacketParser );
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment