コード例 #1
0
        private void VerifyReadWriteThroughObjectOverload(PackStream.PackType type, object value)
        {
            // Given
            var writerMachine = CreateWriterMachine();

            // When
            var writer = writerMachine.Writer();

            writer.Write((object)value);

            // When
            var readerMachine = CreateReaderMachine(writerMachine.GetOutput());
            var reader        = readerMachine.Reader();
            var packedType    = reader.PeekNextType();
            var packedValue   = reader.Read();

            // Then
            packedType.Should().Be(type);
            switch (value)
            {
            case IDictionary dict:
                Assert.Equal(dict, packedValue);
                break;

            case IList list:
                Assert.Equal(list, packedValue);
                break;

            default:
                value.Should().Be(packedValue);
                break;
            }
        }
コード例 #2
0
        protected internal virtual object ReadValue(PackStream.PackType type)
        {
            switch (type)
            {
            case PackStream.PackType.Bytes:
                return(ReadBytes());

            case PackStream.PackType.Null:
                return(ReadNull());

            case PackStream.PackType.Boolean:
                return(ReadBoolean());

            case PackStream.PackType.Integer:
                return(ReadLong());

            case PackStream.PackType.Float:
                return(ReadDouble());

            case PackStream.PackType.String:
                return(ReadString());

            case PackStream.PackType.Map:
                return(ReadMap());

            case PackStream.PackType.List:
                return(ReadList());

            case PackStream.PackType.Struct:
                return(ReadStruct());

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, $"Unknown value type: {type}");
            }
        }
コード例 #3
0
 public override object UnpackValue(PackStream.PackType type)
 {
     if (type == PackStream.PackType.Bytes)
     {
         throw new ProtocolException($"Unsupported type {type}.");
     }
     return(base.UnpackValue(type));
 }
コード例 #4
0
            internal void ShouldPeekTypeCorrectly(byte marker, PackStream.PackType expected)
            {
                var mockInput = IOExtensions.CreateMockStream(marker);
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var nextType = reader.PeekNextType();

                nextType.Should().Be(expected);
                mockInput.Verify(x => x.ReadByte(), Times.Once);
            }
コード例 #5
0
                internal void ShouldPeekTypeCorrectly(byte marker, PackStream.PackType expected)
                {
                    var mockInput = new Mock <IInputStream>();

                    mockInput.Setup(x => x.PeekByte()).Returns(marker);

                    var u = new PackStream.Unpacker(mockInput.Object, null);

                    u.PeekNextType().Should().Be(expected);
                    mockInput.Verify(x => x.PeekByte(), Times.Once);
                }
コード例 #6
0
            public virtual object UnpackValue(PackStream.PackType type)
            {
                switch (type)
                {
                case PackStream.PackType.Bytes:
                    return(_unpacker.UnpackBytes());

                case PackStream.PackType.Null:
                    return(_unpacker.UnpackNull());

                case PackStream.PackType.Boolean:
                    return(_unpacker.UnpackBoolean());

                case PackStream.PackType.Integer:
                    return(_unpacker.UnpackLong());

                case PackStream.PackType.Float:
                    return(_unpacker.UnpackDouble());

                case PackStream.PackType.String:
                    return(_unpacker.UnpackString());

                case PackStream.PackType.Map:
                    return(UnpackMap());

                case PackStream.PackType.List:
                    return(UnpackList());

                case PackStream.PackType.Struct:
                    long size = _unpacker.UnpackStructHeader();
                    switch (_unpacker.UnpackStructSignature())
                    {
                    case NODE:
                        Throw.ProtocolException.IfNotEqual(NodeFields, size, nameof(NodeFields), nameof(size));
                        return(UnpackNode());

                    case RELATIONSHIP:
                        Throw.ProtocolException.IfNotEqual(RelationshipFields, size, nameof(RelationshipFields),
                                                           nameof(size));
                        return(UnpackRelationship());

                    case PATH:
                        Throw.ProtocolException.IfNotEqual(PathFields, size, nameof(PathFields), nameof(size));
                        return(UnpackPath());
                    }
                    break;
                }
                throw new ArgumentOutOfRangeException(nameof(type), type, $"Unknown value type: {type}");
            }
コード例 #7
0
        private void VerifyPeekType(PackStream.PackType type, object value)
        {
            // Given
            var writerMachine = CreateWriterMachine();

            // When
            var writer = writerMachine.Writer();

            writer.Write(value);

            // When
            var readerMachine = CreateReaderMachine(writerMachine.GetOutput());
            var reader        = readerMachine.Reader();

            // Then
            reader.PeekNextType().Should().Be(type);
        }