コード例 #1
0
        public void TestInt32Read()
        {
            var bytes = new byte[] { 0x08, 0x96, 0x01 };

            using (var stream = new MemoryStream(bytes))
            {
                var reader = new ProtobufReader(stream, stream.Length);
                reader.BeginReadMessage(stream.Length);
                reader.FieldNumber.Should().Be(1);
                reader.FieldType.Should().Be(FieldTypes.VarInt);
                var value = reader.ReadInt32();
                value.Should().Be(150);
            }
        }
コード例 #2
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");
            }
        }
コード例 #3
0
        public PrimitiveBlock ReadData()
        {
            reader.BeginReadMessage(length);
            var result = new PrimitiveBlock();

            result.PrimitiveGroup = new List <PrimitiveGroup>();
            while (reader.State == ProtobufReaderState.Field)
            {
                switch (reader.FieldNumber)
                {
                case 1:
                    result.Strings = ReadStringTable();
                    break;

                case 2:
                    result.PrimitiveGroup.Add(ReadPrimitiveGroup());
                    break;

                case 17:
                    result.Granularity = (int)reader.ReadInt64();
                    break;

                case 19:
                    result.LatOffset = reader.ReadInt64();
                    break;

                case 20:
                    result.LonOffset = reader.ReadInt64();
                    break;

                case 18:
                    result.DateGranularity = (int)reader.ReadInt64();
                    break;

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