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; } }
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}"); } }
public override object UnpackValue(PackStream.PackType type) { if (type == PackStream.PackType.Bytes) { throw new ProtocolException($"Unsupported type {type}."); } return(base.UnpackValue(type)); }
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); }
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); }
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}"); }
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); }