public void ShouldRememberFieldTag()
 {
     var fields = new UnknownFieldCollection();
     fields.Add(new MessageTag(1, WireType.Varint), new MessageReader(42));
     Assert.AreEqual(WireType.Varint, fields[0].WireType);
     Assert.AreEqual(1, fields[0].Number);
 }
Ejemplo n.º 2
0
 static UnknownFieldCollection ReadGroup(MessageTag startTag, MessageReader reader)
 {
     var group = new UnknownFieldCollection();
     for(int stop = startTag.WithWireType(WireType.EndGroup), tag = reader.ReadInt32(); tag != stop; tag = reader.ReadInt32())
         group.Add(new MessageTag(tag), reader);
     return group;
 }
        public void ShouldContainFieldAfterAdd()
        {
            var fields = new UnknownFieldCollection();
            fields.Add(new MessageTag(1, WireType.Varint), new MessageReader(42));

            Assert.AreEqual(42, fields[0].Value);
        }
        public void Add_ShouldIncreaseCount()
        {
            var fields = new UnknownFieldCollection();
            fields.Add(new MessageTag(1, WireType.Varint), new MessageReader(42));

            Assert.AreEqual(1, fields.Count);
        }
Ejemplo n.º 5
0
        public void ShouldAddMissingFieldForUnkownEnumValue()
        {
            var missing = new UnknownFieldCollection();
            Serializer.Deserialize<WithEnum>(new MessageReader(8, (byte)WireType.MaxValid + 1), missing);

            Assert.AreEqual(1, missing.Count);
        }
Ejemplo n.º 6
0
        private static UnknownFieldCollection ReadGroup(MessageTag startTag, MessageReader reader)
        {
            UnknownFieldCollection group = new UnknownFieldCollection();

            for (int stop = startTag.WithWireType(WireType.EndGroup),
                 tag = reader.ReadInt32(); tag != stop; tag = reader.ReadInt32())
            {
                group.Add(new MessageTag(tag), reader);
            }

            return(group);
        }
        public void ShouldBeAbleToSerializeConsumedBytes()
        {
            var bytes = new MemoryStream();
            new MessageWriter(bytes)
                .WriteHeader(1, WireType.Varint)
                .WriteVarint(0xbeef)
                .WriteHeader(2, WireType.String)
                .WriteString("Hello World!");
            var fields = new UnknownFieldCollection();
            bytes.Position = 0;
            Serializer.Deserialize<EmptyMessage>(bytes, fields);

            var output = new MemoryStream();
            fields.Serialize(output);
            Assert.AreEqual(bytes.ToArray(), output.ToArray());
        }
        public void ShouldBeEnumerable()
        {
            var bytes = new MemoryStream();
            new MessageWriter(bytes)
                .WriteHeader(1, WireType.Varint)
                .WriteVarint(0xbeef)
                .WriteHeader(2, WireType.String)
                .WriteString("Hello World!");
            var fields = new UnknownFieldCollection();
            bytes.Position = 0;
            Serializer.Deserialize<EmptyMessage>(bytes, fields);

            var list = new List<UnknownField>();
            list.AddRange(fields);

            Assert.AreEqual(2, list.Count);
        }
Ejemplo n.º 9
0
        protected override void SerializeCore(MessageWriter writer)
        {
            UnknownFieldCollection field = (Value as UnknownFieldCollection);

            field.Serialize(writer);
        }