Example #1
0
            private void ShouldReadNumCorrectly(long expected, byte[] data)
            {
                var mockInput = IOExtensions.CreateMockStream(data);
                var reader    = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.Read();

                real.Should().Be(expected);
            }
Example #2
0
            public void ShouldReadNullThroughRead()
            {
                var mockInput =
                    IOExtensions.CreateMockStream(PackStream.Null);
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.Read();

                real.Should().BeNull();
            }
        public object Read(PackStreamReader reader, long size)
        {
            var fieldCount = (int)reader.ReadListHeader();
            var fields     = new object[fieldCount];

            for (var i = 0; i < fieldCount; i++)
            {
                fields[i] = reader.Read();
            }

            return(new RecordMessage(fields));
        }
Example #4
0
            public void ShouldReadStringThroughRead()
            {
                var mockInput =
                    IOExtensions.CreateMockStream("D0 1A 61 62  63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A".ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.Read();

                real.Should().BeOfType <string>();

                var text = (string)real;

                text.Should().Be("abcdefghijklmnopqrstuvwxyz");
            }
Example #5
0
            public void ShouldReadFloatThroughRead()
            {
                var mockInput =
                    IOExtensions.CreateMockStream("C1 3F F1 99 99 99 99 99 9A".ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.Read();

                real.Should().BeOfType <double>();

                var number = (double)real;

                number.Should().Be(1.1);
            }
Example #6
0
            public void ShouldReadBooleanThroughRead(bool value)
            {
                var mockInput =
                    IOExtensions.CreateMockStream(value ? PackStream.True : PackStream.False);
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.Read();

                real.Should().BeOfType <bool>();

                var boolean = (bool)real;

                boolean.Should().Be(value);
            }
Example #7
0
            public void ShouldReadEmptyMap16Correctly()
            {
                var mockInput =
                    IOExtensions.CreateMockStream("D5 00 00 ".ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.Read();

                real.Should().BeAssignableTo <IList <object> >();

                var list = real as IList <object>;

                list.Should().NotBeNull();
                list.Count.Should().Be(0);
            }
Example #8
0
            public void ShouldReadEmptyMap32Correctly()
            {
                var mockInput =
                    IOExtensions.CreateMockStream("DA 00 00 00 00".ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.Read();

                real.Should().BeAssignableTo <IDictionary <string, object> >();

                var map = real as IDictionary <string, object>;

                map.Should().NotBeNull();
                map.Count.Should().Be(0);
            }
Example #9
0
            public void ShouldReadBytesThroughRead()
            {
                var mockInput =
                    IOExtensions.CreateMockStream("CC 01 01".ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.Read();

                real.Should().BeOfType <byte[]>();

                var bytes = real as byte[];

                bytes.Should().NotBeNull();
                bytes.Length.Should().Be(1);
            }
Example #10
0
            public void ShouldReadEmptyStruct16Correctly()
            {
                var mockInput =
                    IOExtensions.CreateMockStream("DD 00 00 01".ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var header    = reader.ReadStructHeader();
                var signature = reader.ReadStructSignature();
                var fields    = new List <object>();

                for (var i = 0; i < header; i++)
                {
                    fields.Add(reader.Read());
                }

                signature.Should().Be(0x01);
                fields.Count.Should().Be(0);
            }
Example #11
0
            public void ShouldReadMap32Correctly()
            {
                var mockInput =
                    IOExtensions.CreateMockStream("D6 00 00 00 03 01 02 03".ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.Read();

                real.Should().BeAssignableTo <IList <object> >();

                var list = real as IList <object>;

                list.Should().NotBeNull();
                list.Count.Should().Be(3);
                list.Should().Contain(1L);
                list.Should().Contain(2L);
                list.Should().Contain(3L);
            }
Example #12
0
            public void ShouldReadTinyMapCorrectly()
            {
                var mockInput =
                    IOExtensions.CreateMockStream(
                        "AF 81 61  01 81 62 01  81 63 03 81  64 04 81 65 05 81 66 06  81 67 07 81  68 08 81 69  09 81 6A 00 81 6B 01 81  6C 02 81 6D  03 81 6E 04  81 6F 05"
                        .ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var real = reader.Read();

                real.Should().BeAssignableTo <IDictionary <string, object> >();

                var map = real as IDictionary <string, object>;

                map.Should().NotBeNull();
                map.Count.Should().Be(15);
                map.Should().ContainKeys("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o");
                map.Should().ContainValues(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 0L);
            }
Example #13
0
            public void ShouldReadTinyStructCorrectly()
            {
                var mockInput =
                    IOExtensions.CreateMockStream("B3 01 01 02 03".ToByteArray());
                var reader = new PackStreamReader(mockInput.Object, BoltReader.StructHandlers);

                var header    = reader.ReadStructHeader();
                var signature = reader.ReadStructSignature();
                var fields    = new List <object>();

                for (var i = 0; i < header; i++)
                {
                    fields.Add(reader.Read());
                }

                signature.Should().Be(0x01);
                fields.Count.Should().Be(3);
                fields.Should().Contain(1L);
                fields.Should().Contain(2L);
                fields.Should().Contain(3L);
            }
Example #14
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));
        }
Example #15
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()));
        }