Packets/VectorParser: set length field before adding new values to the vector
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1271
270642c3-0616-0410-b53a-bc976706d245
prefix_ void senf::MIHPacketType::finalize(packet p)
{
- p->src_mihfId().shrinkLength();
- p->dst_mihfId().shrinkLength();
+ p->src_mihfId().finalizeLength();
+ p->dst_mihfId().finalizeLength();
p->payloadLength_() << p.size() - 8;
p->messageId() << key(p.next(nothrow));
}
default:
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());
+ };
}
}
-prefix_ void senf::DynamicTLVLengthParser::shrink()
+prefix_ void senf::DynamicTLVLengthParser::finalize()
{
value_type v = value();
size_type b = bytes();
prefix_ void senf::GenericTLVPacketType::finalize(packet p)
{
- p->shrinkLength();
+ p->finalizeLength();
}
SENF_PARSER_PRIVATE_BITFIELD ( underflow_flag, 1, bool );
SENF_PARSER_PRIVATE_BITFIELD ( fixed_length_field, 6, unsigned );
- void shrink();
- void maxValue(DynamicTLVLengthParser::value_type v);
+ void finalize();
+ void maxValue(value_type v);
+ value_type maxValue() const;
private:
void resize(size_type size);
};
The size of the length field will be decreased to minimum necessary to hold
the current length value.
*/
- void shrinkLength() {
- length_().shrink();
+ void finalizeLength() {
+ length_().finalize();
};
protected:
senf::VectorParser_Container<ElementParser,AuxPolicy>::shift(iterator pos, size_type n)
{
size_type ix (std::distance(data().begin(),pos.raw()));
- data().insert(pos.raw(),n*ElementParser::fixed_bytes,0);
setSize(size()+n);
+ data().insert(pos.raw(),n*ElementParser::fixed_bytes,0);
return iterator(boost::next(data().begin(),ix),state());
}
template <class ElementParser, class AuxPolicy>
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);
+ data().erase(pos.raw(),boost::next(pos.raw(),n*ElementParser::fixed_bytes));
}
template <class ElementParser, class AuxPolicy>