protozero: Add arrow operator to repeated field iterator
Add an arrow operator to repeated field iterators to make it easier to
work with iterators over non-numeric repeated fields. For example, this
allows you to write iter->data() instead of iter.field().data().
Change-Id: Ib12581cfc528cd7c2a601aca89152de8a10e5e33
diff --git a/src/protozero/proto_decoder_unittest.cc b/src/protozero/proto_decoder_unittest.cc
index 1a63cef..cbcab66 100644
--- a/src/protozero/proto_decoder_unittest.cc
+++ b/src/protozero/proto_decoder_unittest.cc
@@ -90,6 +90,28 @@
EXPECT_FALSE(++it);
}
+TEST(ProtoDecoderTest, RepeatedVariableLengthField) {
+ HeapBuffered<Message> message;
+
+ static constexpr char kTestString[] = "test";
+ static constexpr char kTestString2[] = "honk honk";
+ message->AppendString(1, kTestString);
+ message->AppendString(1, kTestString2);
+ std::vector<uint8_t> proto = message.SerializeAsArray();
+ TypedProtoDecoder<32, false> decoder(proto.data(), proto.size());
+
+ auto it = decoder.GetRepeated<ConstChars>(1);
+ ASSERT_EQ(it->type(), ProtoWireType::kLengthDelimited);
+ ASSERT_EQ(it->size(), sizeof(kTestString) - 1);
+ ASSERT_EQ(it->as_std_string(), std::string(kTestString));
+ ASSERT_EQ((*it).ToStdString(), std::string(kTestString));
+ ++it;
+ ASSERT_EQ(it->type(), ProtoWireType::kLengthDelimited);
+ ASSERT_EQ(it->size(), sizeof(kTestString2) - 1);
+ ASSERT_EQ(it->as_std_string(), std::string(kTestString2));
+ ASSERT_EQ((*it).ToStdString(), std::string(kTestString2));
+}
+
TEST(ProtoDecoderTest, SingleRepeatedFieldWithExpansion) {
Message message;
ScatteredHeapBuffer delegate(512, 512);