public object Read(PackStreamReader reader, long size)
        {
            var urn      = reader.ReadLong();
            var startUrn = reader.ReadLong();
            var endUrn   = reader.ReadLong();
            var relType  = reader.ReadString();
            var props    = reader.ReadMap();

            return(new Relationship(urn, startUrn, endUrn, relType, props));
        }
Esempio n. 2
0
            public void ShouldThrowExceptionIfMarkerByteNotLong()
            {
                var mockInput = IOExtensions.CreateMockStream(PackStream.Bytes16);
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var ex = Xunit.Record.Exception(() => reader.ReadLong());

                ex.Should().BeOfType <ProtocolException>();
            }
Esempio n. 3
0
            [InlineData(0x7F, 127)] // 7F to FF
            public void ShouldReadLongAsTinyByte(byte data, sbyte expected)
            {
                var mockInput = IOExtensions.CreateMockStream(data);
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = (sbyte)reader.ReadLong();

                real.Should().Be(expected);
                mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Once);
            }
Esempio n. 4
0
            public void ShouldReadLongAsLong()
            {
                const long expected  = 1024;
                var        mockInput = IOExtensions.CreateMockStream(PackStream.Int64, PackStreamBitConverter.GetBytes(expected));
                var        reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.ReadLong();

                real.Should().Be(expected);
                mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(2));
            }
Esempio n. 5
0
            public void ShouldReadLongAsSignedByte()
            {
                const sbyte expected  = 1;
                var         mockInput = IOExtensions.CreateMockStream(PackStream.Int8, (byte)expected);
                var         reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = (sbyte)reader.ReadLong();

                real.Should().Be(expected);
                mockInput.Verify(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(2));
            }
Esempio n. 6
0
        public object Read(PackStreamReader reader, long size)
        {
            var urn = reader.ReadLong();

            var numLabels = (int)reader.ReadListHeader();
            var labels    = new List <string>(numLabels);

            for (var i = 0; i < numLabels; i++)
            {
                labels.Add(reader.ReadString());
            }
            var numProps = (int)reader.ReadMapHeader();
            var props    = new Dictionary <string, object>(numProps);

            for (var j = 0; j < numProps; j++)
            {
                var key = reader.ReadString();
                props.Add(key, reader.Read());
            }

            return(new Node(urn, labels, props));
        }
Esempio n. 7
0
        public object Read(PackStreamReader reader, long size)
        {
            // List of unique nodes
            var uniqNodes = new INode[(int)reader.ReadListHeader()];

            for (var i = 0; i < uniqNodes.Length; i++)
            {
                var node = reader.Read() as INode;

                Throw.ProtocolException.IfFalse(node != null, "receivedNode");

                uniqNodes[i] = node;
            }

            // List of unique relationships, without start/end information
            var uniqRels = new Relationship[(int)reader.ReadListHeader()];

            for (var i = 0; i < uniqRels.Length; i++)
            {
                var uniqRel = reader.Read() as Relationship;

                Throw.ProtocolException.IfFalse(uniqRel != null, "receivedUnboundRelationship");

                uniqRels[i] = uniqRel;
            }

            // Path sequence
            var length = (int)reader.ReadListHeader();

            // Knowing the sequence length, we can create the arrays that will represent the nodes, rels and segments in their "path order"
            var segments = new ISegment[length / 2];
            var nodes    = new INode[segments.Length + 1];
            var rels     = new IRelationship[segments.Length];

            var prevNode = uniqNodes[0];

            nodes[0] = prevNode;
            for (var i = 0; i < segments.Length; i++)
            {
                var relIdx   = (int)reader.ReadLong();
                var nextNode = uniqNodes[(int)reader.ReadLong()];  // Start node is always 0, and isn't encoded in the sequence
                // Negative rel index means this rel was traversed "inversed" from its direction
                Relationship rel;
                if (relIdx < 0)
                {
                    rel = uniqRels[(-relIdx) - 1]; // -1 because rel idx are 1-indexed
                    rel.SetStartAndEnd(nextNode.Id, prevNode.Id);
                }
                else
                {
                    rel = uniqRels[relIdx - 1];
                    rel.SetStartAndEnd(prevNode.Id, nextNode.Id);
                }

                nodes[i + 1] = nextNode;
                rels[i]      = rel;
                segments[i]  = new Segment(prevNode, rel, nextNode);
                prevNode     = nextNode;
            }

            return(new Path(segments.ToList(), nodes.ToList(), rels.ToList()));
        }