title: How to encode multiple distinguishable items back to back with protobuf?
body: <p>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:</p>
  
  <p>Here's my .proto file:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>And I have language vernacular style representation objects that help me use them as I would normally:</p>
  
  <pre><code>//name, value
  using reg=std::tuple&lt;std::string, uint64_t&gt;;
  using reg_context=std::list&lt;reg &gt;;
  using mem_region=std::string;
  //name, memory, start, end, ismain
  using image=std::tuple&lt;std::string, mem_region, uint64_t, uint64_t, bool&gt;;
  using mem_region_set=std::list&lt;image &gt;;
  using memory_dump=std::tuple&lt;reg_context, mem_region_set&gt;;
  </code></pre>
  
  <p>Here's the failing test:</p>
  
  <pre><code>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 &lt;&lt; *serialized_regions1 &lt;&lt; *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);
  }
  </code></pre>
  
  <p><strong>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?</strong> The test that I run here results in deserialized_region1/2 each having 5 total images, merely i1, i2, i3, i1, i3</p>