BINLINE void BMessageHeader::read(BBuffer& bbuf) { bbuf.setByteOrder(BBIG_ENDIAN); bool cmpr = bbuf.setCompressInteger(false); bbuf.serialize(magic); switch(magic) { case BMAGIC_BINARY_STREAM: break; case BMAGIC_BINARY_STREAM_LE: magic = BMAGIC_BINARY_STREAM; bbuf.setByteOrder(BLITTLE_ENDIAN); break; default: throw BException(BExceptionC::CORRUPT, L"Stream must start with BYPS or SPYB"); } bbuf.serialize(error); bbuf.serialize(flags); if (flags & BHEADER_FLAG_BYPS_VERSION) { bbuf.serialize(bversion); } bbuf.serialize(version); targetId.serialize(bbuf, bversion); bbuf.serialize(messageId); bbuf.setCompressInteger(cmpr); if (bversion >= BHEADER_BYPS_VERSION_WITH_SESSIONID) { sessionId = BTargetId::readSessionId(bbuf); } }
BINLINE void BMessageHeader::write(BBuffer& bbuf) { bool cmpr = bbuf.setCompressInteger(false); bbuf.setByteOrder(byteOrder); bbuf.serialize(magic); bbuf.serialize(error); bbuf.serialize(flags); if (flags & BHEADER_FLAG_BYPS_VERSION) { bbuf.serialize(bversion); } bbuf.serialize(version); targetId.serialize(bbuf, bversion); bbuf.serialize(messageId); bbuf.setCompressInteger(cmpr); if (bversion >= BHEADER_BYPS_VERSION_WITH_SESSIONID) { BTargetId::writeSessionId(bbuf, sessionId); } }