using senf::PacketTypeMixin<FooPacketType>::nextPacketRange;
using senf::PacketTypeMixin<FooPacketType>::initSize;
using senf::PacketTypeMixin<FooPacketType>::init;
- typedef senf::PacketInterpreter<FooPacketType> interpreter;
- static interpreter::size_type initSize()
+ static size_type initSize()
{ return 4u; }
+
+ // We need to implement initHeadSize() to force the mixin to switch into 'fixed-size'
+ // mode. Otherwise, mixin::nextPacketRange() would query the parser for it's size to find
+ // the header size. Since the parser is VoidPacketParser, the header size would therefore be
+ // 0
+ static size_type initHeadSize()
+ { return initSize(); }
};
typedef senf::ConcretePacket<FooPacketType> FooPacket;
SENF_PARSER_FIELD( length, senf::Int32Parser );
SENF_PARSER_FIELD( reserved, senf::UInt16Parser );
+ SENF_PARSER_INIT() {
+ reserved() << 0xA0A0u;
+ }
+
SENF_PARSER_FINALIZE(BarPacketParser);
};
using mixin::nextPacketType;
using mixin::initSize;
using mixin::init;
- static size_type initSize()
- { return 8u; }
- static void init(packet p) {
- p->reserved() = 0xA0A0u;
- }
static void dump(packet p, std::ostream & os) {
os << "BarPacket:\n"
<< "type: " << p->type() << "\n"
BOOST_CHECK( ! packet.prev(senf::nothrow) );
BOOST_CHECK( packet.next().prev() == packet );
BOOST_CHECK( packet.next() != packet );
+ BOOST_CHECK_EQUAL( std::distance(packet.data().begin(), packet.next().data().begin()), 4 );
+ BOOST_CHECK_EQUAL( std::distance(packet.data().begin(), packet.data().end()), 12 );
+ BOOST_CHECK_EQUAL( std::distance(packet.next().data().begin(), packet.next().data().end()), 8 );
+ BOOST_CHECK( packet.data().end() == packet.next().data().end() );
BOOST_CHECK_EQUAL( packet.size(), 12u );
BOOST_CHECK_EQUAL( packet.next().size(), 8u );
BOOST_CHECK( packet.is<FooPacket>() );
senf::PacketData::byte data[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
BOOST_CHECK_EQUAL( FooPacket::create().size(), 4u );
- BOOST_CHECK_EQUAL( FooPacket::create(FooPacket::noinit).size(), 0u );
+ BOOST_CHECK_EQUAL( FooPacket::create(senf::noinit).size(), 0u );
BOOST_CHECK_THROW( FooPacket::create(2u), senf::TruncatedPacketException );
BOOST_CHECK_EQUAL( FooPacket::create(10u).size(), 10u );
- BOOST_CHECK_EQUAL( FooPacket::create(2u,FooPacket::noinit).size(), 2u );
+ BOOST_CHECK_EQUAL( FooPacket::create(2u,senf::noinit).size(), 2u );
BOOST_CHECK_EQUAL( FooPacket::create(data).size(), 6u );
senf::Packet packet (FooPacket::create());
BOOST_CHECK_EQUAL( FooPacket::createAfter(packet).size(), 4u );
BOOST_CHECK_EQUAL( packet.size(), 8u );
- BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,FooPacket::noinit).size(), 0u );
+ BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,senf::noinit).size(), 0u );
BOOST_CHECK_EQUAL( packet.size(), 4u );
BOOST_CHECK_THROW( FooPacket::createAfter(packet,2u), senf::TruncatedPacketException );
BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,10u).size(), 10u );
BOOST_CHECK_EQUAL( packet.size(), 14u );
- BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,2u,FooPacket::noinit).size(), 2u );
+ BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,2u,senf::noinit).size(), 2u );
BOOST_CHECK_EQUAL( packet.size(), 6u );
BOOST_CHECK_EQUAL( FooPacket::createAfter(packet,data).size(), 6u );
BOOST_CHECK_EQUAL( FooPacket::createBefore(packet).size(), 14u );
BOOST_CHECK_EQUAL( packet.size(), 10u );
- BOOST_CHECK_EQUAL( FooPacket::createBefore(packet,FooPacket::noinit).size(), 10u );
+ BOOST_CHECK_EQUAL( FooPacket::createBefore(packet,senf::noinit).size(), 10u );
BOOST_CHECK_EQUAL( packet.size(), 10u );
BOOST_CHECK( packet.clone() != packet );