mirror of
https://github.com/fraillt/bitsery.git
synced 2026-09-14 22:34:33 +00:00
multiple breaking change improvements
This commit is contained in:
committed by
Mindaugas Vinkelis
parent
57dd028b7a
commit
1822796f2e
@@ -32,114 +32,73 @@ struct DataV1 {
|
||||
int32_t v1;
|
||||
};
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s, DataV1& o) {
|
||||
s.value4b(o.v1);
|
||||
}
|
||||
|
||||
struct DataV2 {
|
||||
int32_t v1;
|
||||
int32_t v2;
|
||||
};
|
||||
|
||||
template <typename S>
|
||||
void serialize(S& s, DataV2& o) {
|
||||
s.value4b(o.v1);
|
||||
s.value4b(o.v2);
|
||||
}
|
||||
|
||||
struct DataV3 {
|
||||
int32_t v1;
|
||||
int32_t v2;
|
||||
int32_t v3;
|
||||
template <typename S>
|
||||
void serialize(S& s) {
|
||||
s.value4b(v1);
|
||||
s.value4b(v2);
|
||||
s.value4b(v3);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
TEST(SerializeExtensionGrowable, WriteSessionsDataAtBufferEndAfterFlush) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
auto& ser = ctx.createSerializer();
|
||||
TEST(SerializeExtensionGrowable, SessionsLengthIsStoredWith4BytesBeforeSessionDataStarts) {
|
||||
SerializationContext ctx;
|
||||
auto ser = ctx.createSerializer();
|
||||
//session cannot be empty
|
||||
ser.ext(int8_t{}, Growable{}, [&ser] (int8_t& v) {
|
||||
ser.value2b(int16_t{1});
|
||||
ser.ext(int8_t{2}, Growable{}, [] (decltype(ser)& ser, int8_t& v) {
|
||||
ser.value1b(v);
|
||||
});
|
||||
ser.value1b(int8_t{3});
|
||||
|
||||
EXPECT_THAT(ctx.getBufferSize(), Eq(1u));
|
||||
ctx.bw->flush();
|
||||
EXPECT_THAT(ctx.getBufferSize(), Gt(1u));
|
||||
}
|
||||
|
||||
|
||||
TEST(SerializeExtensionGrowable, SessionDataConsistOfSessionsEndPosAnd4BytesSessionsDataOffset) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
|
||||
|
||||
constexpr size_t DATA_SIZE = 4;
|
||||
int32_t data{};
|
||||
|
||||
auto& ser = ctx.createSerializer();
|
||||
ser.ext(data, Growable{}, [&ser](int32_t & v) { ser.value4b(v);});
|
||||
ctx.createDeserializer();//to flush data and create buffer reader
|
||||
|
||||
EXPECT_THAT(ctx.getBufferSize(), Eq(1+4 + DATA_SIZE));
|
||||
|
||||
//read value back
|
||||
auto& br = *(ctx.br);
|
||||
br.readBytes<DATA_SIZE>(data);
|
||||
|
||||
size_t sessionEnd{};
|
||||
//there should start session data with first size of session
|
||||
bitsery::details::readSize(br, sessionEnd, 1000000u);
|
||||
EXPECT_THAT(sessionEnd, Eq(DATA_SIZE));
|
||||
//this is the the offset from the end of buffer where actual data ends
|
||||
uint32_t sessionsOffset{};//bufferEnd - sessionsOffset = dataEnd
|
||||
br.readBytes<4>(sessionsOffset);
|
||||
EXPECT_THAT(sessionsOffset, Eq(1+4));//1byte for session info, 4 bytes for session offset variable
|
||||
auto writtenSize = ctx.bw->writtenBytesCount();
|
||||
auto dSize = writtenSize - sessionsOffset;
|
||||
EXPECT_THAT(dSize, Eq(DATA_SIZE));
|
||||
}
|
||||
|
||||
TEST(SerializeExtensionGrowable, WhenNestedSessionsThenStoreEachDepthAndSize) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
DataV3 data{19457,846, 498418};
|
||||
ctx.createSerializer();
|
||||
ctx.bw->beginSession();
|
||||
ctx.bw->writeBytes<4>(data.v1);
|
||||
ctx.bw->beginSession();
|
||||
ctx.bw->writeBytes<4>(data.v2);
|
||||
ctx.bw->endSession();
|
||||
ctx.bw->beginSession();
|
||||
ctx.bw->writeBytes<4>(data.v3);
|
||||
ctx.bw->endSession();
|
||||
ctx.bw->endSession();
|
||||
DataV3 res{};
|
||||
ctx.createDeserializer();//to flush data and create buffer reader
|
||||
ctx.br->readBytes<4>(res.v1);
|
||||
ctx.br->readBytes<4>(res.v2);
|
||||
ctx.br->readBytes<4>(res.v3);
|
||||
//read data correctly
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
EXPECT_THAT(res.v3, Eq(data.v3));
|
||||
size_t sessionEnd[3];
|
||||
//read sessions sizes
|
||||
bitsery::details::readSize(*(ctx.br), sessionEnd[0],10000000u);
|
||||
bitsery::details::readSize(*(ctx.br), sessionEnd[1],10000000u);
|
||||
bitsery::details::readSize(*(ctx.br), sessionEnd[2],10000000u);
|
||||
EXPECT_THAT(sessionEnd[0], Eq(12));
|
||||
EXPECT_THAT(sessionEnd[1], Eq(8));
|
||||
EXPECT_THAT(sessionEnd[2], Eq(12));
|
||||
auto des = ctx.createDeserializer();
|
||||
uint8_t res1b{};
|
||||
uint16_t res2b{};
|
||||
uint32_t res4b{};
|
||||
des.value2b(res2b);
|
||||
EXPECT_THAT(res2b, Eq(1));
|
||||
des.value4b(res4b);
|
||||
EXPECT_THAT(res4b, Eq(1+4));//size + 4bytes
|
||||
des.value1b(res1b);
|
||||
EXPECT_THAT(res1b, Eq(2));
|
||||
des.value1b(res1b);
|
||||
EXPECT_THAT(res1b, Eq(3));
|
||||
EXPECT_THAT(ctx.bw->writtenBytesCount(), Eq(8));
|
||||
}
|
||||
|
||||
TEST(SerializeExtensionGrowable, MultipleSessionsReadSameVersionData) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
SerializationContext ctx;
|
||||
DataV2 data{8454,987451};
|
||||
ctx.createSerializer();
|
||||
auto& bw = (*ctx.bw);
|
||||
auto ser = ctx.createSerializer();
|
||||
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v1);
|
||||
bw.writeBytes<4>(data.v2);
|
||||
bw.endSession();
|
||||
bitsery::FtorExtObject<Growable>{}(ser, data);
|
||||
}
|
||||
//create more sessions that can fit in 2 bytes
|
||||
ctx.createDeserializer();//to flush data and create buffer reader
|
||||
ctx.createDeserializer();
|
||||
DataV2 res{};
|
||||
auto& br = (*ctx.br);
|
||||
auto des = ctx.createDeserializer();
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v1);
|
||||
br.readBytes<4>(res.v2);
|
||||
br.endSession();
|
||||
bitsery::FtorExtObject<Growable>{}(des, res);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
}
|
||||
@@ -147,53 +106,37 @@ TEST(SerializeExtensionGrowable, MultipleSessionsReadSameVersionData) {
|
||||
}
|
||||
|
||||
TEST(SerializeExtensionGrowable, MultipleSessionsReadNewerVersionData) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
DataV3 data{8454,987451,54};
|
||||
ctx.createSerializer();
|
||||
auto& bw = (*ctx.bw);
|
||||
SerializationContext ctx;
|
||||
DataV3 data{8454,987451, 45612};
|
||||
auto ser = ctx.createSerializer();
|
||||
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v1);
|
||||
bw.writeBytes<4>(data.v2);
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.endSession();
|
||||
bitsery::FtorExtObject<Growable>{}(ser, data);
|
||||
}
|
||||
//create more sessions that can fit in 2 bytes
|
||||
ctx.createDeserializer();//to flush data and create buffer reader
|
||||
ctx.createDeserializer();
|
||||
DataV2 res{};
|
||||
auto& br = (*ctx.br);
|
||||
auto des = ctx.createDeserializer();
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v1);
|
||||
br.readBytes<4>(res.v2);
|
||||
br.endSession();
|
||||
bitsery::FtorExtObject<Growable>{}(des, res);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
}
|
||||
EXPECT_THAT(br.isCompletedSuccessfully(), Eq(true));
|
||||
EXPECT_THAT(ctx.br->isCompletedSuccessfully(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(SerializeExtensionGrowable, MultipleSessionsReadOlderVersionData) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
SerializationContext ctx;
|
||||
DataV2 data{8454,987451};
|
||||
ctx.createSerializer();
|
||||
auto& bw = (*ctx.bw);
|
||||
auto ser = ctx.createSerializer();
|
||||
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v1);
|
||||
bw.writeBytes<4>(data.v2);
|
||||
bw.endSession();
|
||||
bitsery::FtorExtObject<Growable>{}(ser, data);
|
||||
}
|
||||
//create more sessions that can fit in 2 bytes
|
||||
ctx.createDeserializer();//to flush data and create buffer reader
|
||||
DataV3 res{4798,657891,985};
|
||||
auto& br = (*ctx.br);
|
||||
ctx.createDeserializer();
|
||||
DataV3 res{};
|
||||
auto des = ctx.createDeserializer();
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v1);
|
||||
br.readBytes<4>(res.v2);
|
||||
br.readBytes<4>(res.v3);
|
||||
br.endSession();
|
||||
bitsery::FtorExtObject<Growable>{}(des, res);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
EXPECT_THAT(res.v3, Eq(0));
|
||||
@@ -202,225 +145,94 @@ TEST(SerializeExtensionGrowable, MultipleSessionsReadOlderVersionData) {
|
||||
}
|
||||
|
||||
TEST(SerializeExtensionGrowable, MultipleNestedSessionsReadSameVersionData) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
SerializationContext ctx;
|
||||
DataV2 data{8454,987451};
|
||||
ctx.createSerializer();
|
||||
auto& bw = (*ctx.bw);
|
||||
for (auto i = 0; i < 2; ++i) {
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v1);
|
||||
bw.writeBytes<4>(data.v2);
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v1);
|
||||
bw.writeBytes<4>(data.v2);
|
||||
bw.endSession();
|
||||
bw.endSession();
|
||||
auto ser = ctx.createSerializer();
|
||||
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
ser.ext(data, Growable{}, [](decltype(ser)& ser, DataV2& o) {
|
||||
ser.value4b(o.v1);
|
||||
ser.value4b(o.v2);
|
||||
bitsery::FtorExtObject<Growable>{}(ser, o);
|
||||
});
|
||||
}
|
||||
//create more sessions that can fit in 2 bytes
|
||||
ctx.createDeserializer();//to flush data and create buffer reader
|
||||
ctx.createDeserializer();
|
||||
DataV2 res{};
|
||||
auto& br = (*ctx.br);
|
||||
for (auto i = 0; i < 2; ++i) {
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v1);
|
||||
br.readBytes<4>(res.v2);
|
||||
auto des = ctx.createDeserializer();
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
des.ext(res, Growable{}, [&res, &data](decltype(des)& des, DataV2& o) {
|
||||
des.value4b(o.v1);
|
||||
des.value4b(o.v2);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v1);
|
||||
br.readBytes<4>(res.v2);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
br.endSession();
|
||||
br.endSession();
|
||||
bitsery::FtorExtObject<Growable>{}(des, o);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
});
|
||||
}
|
||||
EXPECT_THAT(ctx.br->isCompletedSuccessfully(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(SerializeExtensionGrowable, MultipleNestedSessionsReadNewerVersionData) {
|
||||
SerializationContext ctx;
|
||||
DataV3 data{8454,987451, 54124};
|
||||
auto ser = ctx.createSerializer();
|
||||
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
ser.ext(data, Growable{}, [](decltype(ser)& ser, DataV3& o) {
|
||||
ser.value4b(o.v1);
|
||||
ser.value4b(o.v2);
|
||||
bitsery::FtorExtObject<Growable>{}(ser, o);
|
||||
//new fields can only be added at the end
|
||||
ser.value4b(o.v3);
|
||||
});
|
||||
}
|
||||
ctx.createDeserializer();
|
||||
DataV2 res{};
|
||||
auto des = ctx.createDeserializer();
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
des.ext(res, Growable{}, [&res, &data](decltype(des)& des, DataV2& o) {
|
||||
des.value4b(o.v1);
|
||||
des.value4b(o.v2);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
bitsery::FtorExtObject<Growable>{}(des, o);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
});
|
||||
}
|
||||
EXPECT_THAT(ctx.br->isCompletedSuccessfully(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(SerializeExtensionGrowable, MultipleNestedSessionsReadOlderVersionData) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
SerializationContext ctx;
|
||||
DataV2 data{8454,987451};
|
||||
ctx.createSerializer();
|
||||
auto& bw = (*ctx.bw);
|
||||
for (auto i = 0; i < 5; ++i) {
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v1);
|
||||
bw.endSession();
|
||||
bw.writeBytes<4>(data.v2);
|
||||
}
|
||||
auto ser = ctx.createSerializer();
|
||||
|
||||
//create more sessions that can fit in 2 bytes
|
||||
ctx.createDeserializer();//to flush data and create buffer reader
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
ser.ext(data, Growable{}, [](decltype(ser)& ser, DataV2& o) {
|
||||
ser.value4b(o.v1);
|
||||
ser.value4b(o.v2);
|
||||
bitsery::FtorExtObject<Growable>{}(ser, o);
|
||||
});
|
||||
}
|
||||
ctx.createDeserializer();
|
||||
DataV3 res{};
|
||||
auto& br = (*ctx.br);
|
||||
for (auto i = 0; i < 5; ++i) {
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v1);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
//new flow
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v3);
|
||||
EXPECT_THAT(res.v3, Eq(0));
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v3);
|
||||
EXPECT_THAT(res.v3, Eq(0));
|
||||
br.endSession();
|
||||
br.endSession();
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v3);
|
||||
EXPECT_THAT(res.v3, Eq(0));
|
||||
br.endSession();
|
||||
br.endSession();
|
||||
br.readBytes<4>(res.v2);
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
}
|
||||
EXPECT_THAT(ctx.br->isCompletedSuccessfully(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(SerializeExtensionGrowable, MultipleNestedSessionsReadNewerVersionData1) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
DataV3 data{8454,987451,54};
|
||||
ctx.createSerializer();
|
||||
auto& bw = (*ctx.bw);
|
||||
for (auto i = 0; i < 2; ++i) {
|
||||
bw.beginSession();
|
||||
{
|
||||
bw.writeBytes<4>(data.v1);
|
||||
bw.writeBytes<4>(data.v2);
|
||||
//new flow
|
||||
bw.beginSession();
|
||||
{
|
||||
bw.writeBytes<4>(data.v3);
|
||||
}
|
||||
bw.endSession();
|
||||
bw.beginSession();
|
||||
{
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.beginSession();
|
||||
{
|
||||
bw.beginSession();
|
||||
{
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.writeBytes<4>(data.v3);
|
||||
}
|
||||
bw.endSession();
|
||||
bw.writeBytes<4>(data.v3);
|
||||
}
|
||||
bw.endSession();
|
||||
}
|
||||
bw.endSession();
|
||||
bw.writeBytes<4>(data.v3);
|
||||
}
|
||||
bw.endSession();
|
||||
bw.writeBytes<4>(data.v2);
|
||||
}
|
||||
//create more sessions that can fit in 2 bytes
|
||||
ctx.createDeserializer();//to flush data and create buffer reader
|
||||
DataV2 res{};
|
||||
auto& br = (*ctx.br);
|
||||
for (auto i = 0; i < 2; ++i) {
|
||||
br.beginSession();
|
||||
{
|
||||
br.readBytes<4>(res.v1);
|
||||
br.readBytes<4>(res.v2);
|
||||
auto des = ctx.createDeserializer();
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
des.ext(res, Growable{}, [&res, &data](decltype(des)& des, DataV3& o) {
|
||||
des.value4b(o.v1);
|
||||
des.value4b(o.v2);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
}
|
||||
br.endSession();
|
||||
br.readBytes<4>(res.v2);
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
}
|
||||
EXPECT_THAT(ctx.br->isCompletedSuccessfully(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(SerializeExtensionGrowable, MultipleNestedSessionsReadNewerVersionData2) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
DataV3 data{8454,987451,54};
|
||||
ctx.createSerializer();
|
||||
auto& bw = (*ctx.bw);
|
||||
for (auto i = 0; i < 2; ++i) {
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v1);
|
||||
bw.writeBytes<4>(data.v2);
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v1);
|
||||
bw.writeBytes<4>(data.v2);
|
||||
|
||||
//new flow
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.endSession();
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.beginSession();
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.endSession();
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.endSession();
|
||||
bw.endSession();
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.endSession();
|
||||
bw.writeBytes<4>(data.v2);
|
||||
|
||||
//new flow
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.endSession();
|
||||
bw.writeBytes<4>(data.v3);
|
||||
bw.endSession();
|
||||
}
|
||||
//create more sessions that can fit in 2 bytes
|
||||
ctx.createDeserializer();//to flush data and create buffer reader
|
||||
DataV2 res{};
|
||||
auto& br = (*ctx.br);
|
||||
for (auto i = 0; i < 2; ++i) {
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v1);
|
||||
br.readBytes<4>(res.v2);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v1);
|
||||
br.readBytes<4>(res.v2);
|
||||
bitsery::FtorExtObject<Growable>{}(des, o);
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
br.endSession();
|
||||
br.readBytes<4>(res.v2);
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
br.endSession();
|
||||
}
|
||||
EXPECT_THAT(ctx.br->isCompletedSuccessfully(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(SerializeExtensionGrowable, SessionsStartsAtEndOfSerialization) {
|
||||
BasicSerializationContext<SessionsEnabledConfig, void> ctx;
|
||||
DataV2 data{8454,987451};
|
||||
ctx.createSerializer();
|
||||
auto& bw = (*ctx.bw);
|
||||
for (auto i = 0; i < 100; ++i)
|
||||
bw.writeBytes<4>(data.v1);
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
bw.beginSession();
|
||||
bw.writeBytes<4>(data.v1);
|
||||
bw.writeBytes<4>(data.v2);
|
||||
bw.endSession();
|
||||
}
|
||||
//create more sessions that can fit in 2 bytes
|
||||
ctx.createDeserializer();//to flush data and create buffer reader
|
||||
DataV2 res{};
|
||||
auto& br = (*ctx.br);
|
||||
for (auto i = 0; i < 100; ++i)
|
||||
br.readBytes<4>(res.v1);
|
||||
for (auto i = 0; i < 10; ++i) {
|
||||
br.beginSession();
|
||||
br.readBytes<4>(res.v1);
|
||||
br.readBytes<4>(res.v2);
|
||||
br.endSession();
|
||||
EXPECT_THAT(res.v1, Eq(data.v1));
|
||||
EXPECT_THAT(res.v2, Eq(data.v2));
|
||||
EXPECT_THAT(res.v3, Eq(0));
|
||||
//new fields can only be added at the end
|
||||
des.value4b(o.v3);
|
||||
EXPECT_THAT(res.v3, Eq(0));
|
||||
});
|
||||
}
|
||||
EXPECT_THAT(ctx.br->isCompletedSuccessfully(), Eq(true));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user