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

Packets/80221Bundle: one more fix for DynamicTLVLengthParser

Packets/VectorParser: set length field before adding new values to the vector
parent 552c8c6f
No related branches found
No related tags found
No related merge requests found
...@@ -123,8 +123,8 @@ prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os) ...@@ -123,8 +123,8 @@ prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os)
prefix_ void senf::MIHPacketType::finalize(packet p) prefix_ void senf::MIHPacketType::finalize(packet p)
{ {
p->src_mihfId().shrinkLength(); p->src_mihfId().finalizeLength();
p->dst_mihfId().shrinkLength(); p->dst_mihfId().finalizeLength();
p->payloadLength_() << p.size() - 8; p->payloadLength_() << p.size() - 8;
p->messageId() << key(p.next(nothrow)); p->messageId() << key(p.next(nothrow));
} }
......
...@@ -92,7 +92,27 @@ prefix_ void senf::DynamicTLVLengthParser::value(value_type const & v) ...@@ -92,7 +92,27 @@ prefix_ void senf::DynamicTLVLengthParser::value(value_type const & v)
default: default:
throw( TLVLengthException()); throw( TLVLengthException());
}; };
underflow_flag() = v < 128; underflow_flag() = (v <= 128);
}
prefix_ senf::DynamicTLVLengthParser::value_type senf::DynamicTLVLengthParser::maxValue()
const
{
switch (bytes() ) {
case 1:
return 128;
case 2:
return UInt8Parser::max_value + 128;
case 3:
return UInt16Parser::max_value + 128;
case 4:
return UInt24Parser::max_value + 128;
case 5:
return UInt32Parser::max_value;
default:
throw( TLVLengthException());
};
} }
...@@ -110,7 +130,7 @@ prefix_ void senf::DynamicTLVLengthParser::init() const ...@@ -110,7 +130,7 @@ prefix_ void senf::DynamicTLVLengthParser::init() const
} }
prefix_ void senf::DynamicTLVLengthParser::shrink() prefix_ void senf::DynamicTLVLengthParser::finalize()
{ {
value_type v = value(); value_type v = value();
size_type b = bytes(); size_type b = bytes();
...@@ -199,7 +219,7 @@ prefix_ void senf::GenericTLVPacketType::dump(packet p, std::ostream & os) ...@@ -199,7 +219,7 @@ prefix_ void senf::GenericTLVPacketType::dump(packet p, std::ostream & os)
prefix_ void senf::GenericTLVPacketType::finalize(packet p) prefix_ void senf::GenericTLVPacketType::finalize(packet p)
{ {
p->shrinkLength(); p->finalizeLength();
} }
......
...@@ -68,8 +68,9 @@ namespace senf { ...@@ -68,8 +68,9 @@ namespace senf {
SENF_PARSER_PRIVATE_BITFIELD ( underflow_flag, 1, bool ); SENF_PARSER_PRIVATE_BITFIELD ( underflow_flag, 1, bool );
SENF_PARSER_PRIVATE_BITFIELD ( fixed_length_field, 6, unsigned ); SENF_PARSER_PRIVATE_BITFIELD ( fixed_length_field, 6, unsigned );
void shrink(); void finalize();
void maxValue(DynamicTLVLengthParser::value_type v); void maxValue(value_type v);
value_type maxValue() const;
private: private:
void resize(size_type size); void resize(size_type size);
}; };
...@@ -131,8 +132,8 @@ namespace senf { ...@@ -131,8 +132,8 @@ namespace senf {
The size of the length field will be decreased to minimum necessary to hold The size of the length field will be decreased to minimum necessary to hold
the current length value. the current length value.
*/ */
void shrinkLength() { void finalizeLength() {
length_().shrink(); length_().finalize();
}; };
protected: protected:
......
...@@ -64,8 +64,8 @@ prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator ...@@ -64,8 +64,8 @@ prefix_ typename senf::VectorParser_Container<ElementParser,AuxPolicy>::iterator
senf::VectorParser_Container<ElementParser,AuxPolicy>::shift(iterator pos, size_type n) senf::VectorParser_Container<ElementParser,AuxPolicy>::shift(iterator pos, size_type n)
{ {
size_type ix (std::distance(data().begin(),pos.raw())); size_type ix (std::distance(data().begin(),pos.raw()));
data().insert(pos.raw(),n*ElementParser::fixed_bytes,0);
setSize(size()+n); setSize(size()+n);
data().insert(pos.raw(),n*ElementParser::fixed_bytes,0);
return iterator(boost::next(data().begin(),ix),state()); return iterator(boost::next(data().begin(),ix),state());
} }
......
...@@ -247,8 +247,8 @@ prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::insert(itera ...@@ -247,8 +247,8 @@ prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::insert(itera
template <class ElementParser, class AuxPolicy> template <class ElementParser, class AuxPolicy>
prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::erase(iterator pos, size_type n) prefix_ void senf::VectorParser_Container<ElementParser,AuxPolicy>::erase(iterator pos, size_type n)
{ {
data().erase(pos.raw(),boost::next(pos.raw(),n*ElementParser::fixed_bytes));
setSize(size()-n); setSize(size()-n);
data().erase(pos.raw(),boost::next(pos.raw(),n*ElementParser::fixed_bytes));
} }
template <class ElementParser, class AuxPolicy> template <class ElementParser, class AuxPolicy>
......
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