Пример #1
0
        public void TestStringRead()
        {
            var bytes = new byte[] { 0x12, 0x07, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67 };

            using (var stream = new MemoryStream(bytes))
            {
                var reader = new ProtobufReader(stream, stream.Length);
                reader.BeginReadMessage(stream.Length);
                reader.FieldNumber.Should().Be(2);
                reader.FieldType.Should().Be(FieldTypes.LengthDelimited);
                var value = reader.ReadString();
                value.Should().Be("testing");
            }
        }
Пример #2
0
        private string[] ReadStringTable()
        {
            reader.BeginReadMessage();
            var strings = new List <string>();

            while (reader.State == ProtobufReaderState.Field)
            {
                switch (reader.FieldNumber)
                {
                case 1:
                    strings.Add(reader.ReadString());
                    break;

                default:
                    reader.Skip();
                    break;
                }
            }
            reader.EndReadMessage();
            return(strings.ToArray());
        }