So, I have a unit test where I'm trying to ensure that encoding and
decoding is sound. Basically, I kind of want to be able to serialize
multiple different C++ objects into a string, and then write that string
into a file. This is what I have so far:
Here's my .proto file:
message Register {
required string regname = 1;
required uint64 regvalue = 2;
}
message RegisterContext {
repeated Register elem = 1;
}
message MemoryRegion {
repeated bytes elem = 1;
}
message Image {
required string imgName = 1;
required MemoryRegion Memory = 2;
required uint64 MemStart = 3;
required uint64 MemEnd = 4;
required bool isMain = 5;
}
message MemoryRegions {
repeated Image elem = 1;
}
message MemoryDump {
required RegisterContext context = 1;
required MemoryRegions state = 2;
}
And I have language vernacular style representation objects that help me
use them as I would normally.
//name, value
using reg=std::tuple<std::string, uint64_t>;
using reg_context=std::list<reg >;
using mem_region=std::string;
//name, memory, start, end, ismain
using image=std::tuple<std::string, mem_region, uint64_t, uint64_t, bool>;
using mem_region_set=std::list<image >;
using memory_dump=std::tuple<reg_context, mem_region_set>;
TEST(SerializationTests, test_contiguous_memory_differentiated) {
mem_region region="\x25\x26\x27";
image i1{std::make_tuple(std::string("img1"), region, 0, 1, false)},
i2{std::make_tuple(std::string("img2"), region+"\x28", 0, 1, false)},
i3{std::make_tuple(std::string("img3"), region+"\x29", 0, 1, false)};
mem_region_set regions1{i1, i2, i3}, regions2{i1, i3};
auto serialized_regions1=serialize_memory_regions(regions1);
auto serialized_regions2=serialize_memory_regions(regions2);
std::stringstream ss;
ss << *serialized_regions1 << *serialized_regions2;
auto concatenated=ss.str();
auto deserialized_region1=unpack_memory_regions(concatenated);
ASSERT_EQ(deserialized_region1, regions1);
auto deserialized_region2=unpack_memory_regions(concatenated);
ASSERT_EQ(deserialized_region2, regions2);
}
How do I serialize multiple objects so that, whether I put them into a
string stream or a ofstream, they come back out as being distict? The test
that I run here results in deserialized_region1/2 each having 5 total
images, merely i1, i2, i3, i1, i3
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.