예제 #1
0
        /// <inheritdoc />
        protected override async Task <P> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var operatorName = (string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false);

            var argsLength = (int)await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            var args = new object[argsLength];

            for (var i = 0; i < argsLength; i++)
            {
                args[i] = await reader.ReadAsync(stream).ConfigureAwait(false);
            }

            if (operatorName == "and" || operatorName == "or")
            {
                return(new P(operatorName, (P)args[0], (P)args[1]));
            }

            if (operatorName == "not")
            {
                return(new P(operatorName, (P)args[0]));
            }

            if (argsLength == 1)
            {
                if (DataType == DataType.TextP)
                {
                    return(new TextP(operatorName, (string)args[0]));
                }
                return(new P(operatorName, args[0]));
            }
            return(new P(operatorName, args));
        }
예제 #2
0
        /// <inheritdoc />
        protected override async Task<char> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var firstByte = await stream.ReadByteAsync().ConfigureAwait(false);
            var byteLength = 1;
            // A byte with the first byte ON (10000000) signals that more bytes are needed to represent the UTF-8 char
            if ((firstByte & 0x80) > 0)
            {
                if ((firstByte & 0xf0) == 0xf0)
                { // 0xf0 = 11110000
                    byteLength = 4;
                } else if ((firstByte & 0xe0) == 0xe0)
                { //11100000
                    byteLength = 3;
                } else if ((firstByte & 0xc0) == 0xc0)
                { //11000000
                    byteLength = 2;
                }
            }

            byte[] bytes;
            if (byteLength == 1)
            {
                bytes = new[] {firstByte};
            }
            else
            {
                bytes = new byte[byteLength];
                bytes[0] = firstByte;
                await stream.ReadAsync(bytes, 1, byteLength - 1).ConfigureAwait(false);
            }

            return Encoding.UTF8.GetChars(bytes)[0];
        }
예제 #3
0
        public override async Task <object> ReadValueAsync(Stream stream, GraphBinaryReader reader, bool nullable)
        {
            if (nullable)
            {
                var valueFlag = await stream.ReadByteAsync().ConfigureAwait(false);

                if ((valueFlag & 1) == 1)
                {
                    return(null);
                }
            }

            // Read the byte length of the value bytes
            var valueLength = await stream.ReadIntAsync().ConfigureAwait(false);

            if (valueLength <= 0)
            {
                throw new IOException($"Unexpected value length: {valueLength}");
            }

            if (valueLength > stream.Length)
            {
                throw new IOException($"Not enough readable bytes: {valueLength} (expected: {stream.Length})");
            }

            var name = (string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false);

            var birthDate =
                (DateTimeOffset)await reader.ReadValueAsync <DateTimeOffset>(stream, false).ConfigureAwait(false);

            return(new SamplePerson(name, birthDate));
        }
예제 #4
0
        /// <inheritdoc />
        protected override async Task <BigInteger> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var length = (int)await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            var bytes = await stream.ReadAsync(length).ConfigureAwait(false);

            return(new BigInteger(bytes.Reverse().ToArray()));
        }
예제 #5
0
        /// <inheritdoc />
        protected override async Task <Binding> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var key = (string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false);

            var value = await reader.ReadAsync(stream).ConfigureAwait(false);

            return(new Binding(key, value));
        }
예제 #6
0
        /// <inheritdoc />
        protected override async Task <TimeSpan> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var seconds = await stream.ReadLongAsync().ConfigureAwait(false);

            var nanoseconds = await stream.ReadIntAsync().ConfigureAwait(false);

            return(TimeSpan.FromSeconds(seconds) + TimeSpan.FromMilliseconds(nanoseconds / 1_000_000));
        }
예제 #7
0
        /// <inheritdoc />
        protected override async Task <Traverser> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var bulk = (long)await reader.ReadValueAsync <long>(stream, false).ConfigureAwait(false);

            var v = await reader.ReadAsync(stream).ConfigureAwait(false);

            return(new Traverser(v, bulk));
        }
예제 #8
0
        /// <inheritdoc />
        protected override async Task <decimal> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var scale = (int)await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            var unscaled = (BigInteger)await reader.ReadValueAsync <BigInteger>(stream, false).ConfigureAwait(false);

            return(ConvertScaleAndUnscaledValue(scale, unscaled));
        }
예제 #9
0
        /// <inheritdoc />
        protected override async Task <byte[]> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var length = (int)await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            var buffer = new byte[length];
            await stream.ReadAsync(buffer, 0, length).ConfigureAwait(false);

            return(buffer);
        }
예제 #10
0
        /// <inheritdoc />
        protected override async Task <string> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var length = (int)await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            var bytes = new byte[length];
            await stream.ReadAsync(bytes, 0, length).ConfigureAwait(false);

            return(Encoding.UTF8.GetString(bytes));
        }
예제 #11
0
        /// <inheritdoc />
        protected override async Task <Property> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var p = new Property((string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false),
                                 await reader.ReadAsync(stream).ConfigureAwait(false));

            // discard parent element
            await reader.ReadAsync(stream).ConfigureAwait(false);

            return(p);
        }
예제 #12
0
        /// <inheritdoc />
        protected override async Task <Vertex> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var v = new Vertex(await reader.ReadAsync(stream).ConfigureAwait(false),
                               (string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false));

            // discard properties
            await reader.ReadAsync(stream).ConfigureAwait(false);

            return(v);
        }
예제 #13
0
        public override async Task <object> ReadAsync(Stream stream, GraphBinaryReader reader)
        {
            // {custom type info}, {value_flag} and {value}
            // No custom_type_info
            if (await stream.ReadIntAsync().ConfigureAwait(false) != 0)
            {
                throw new IOException("{custom_type_info} should not be provided for this custom type");
            }

            return(await ReadValueAsync(stream, reader, true).ConfigureAwait(false));
        }
예제 #14
0
        /// <inheritdoc />
        protected override async Task <ILambda> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var language = (string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false);

            var expression = (string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false);

            // discard the arguments
            await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            return(new StringBasedLambda(expression, language));
        }
        /// <inheritdoc />
        public override async Task <object> ReadAsync(Stream stream, GraphBinaryReader reader)
        {
            var customTypeInfo = await stream.ReadIntAsync().ConfigureAwait(false);

            if (customTypeInfo != _type.TypeId)
            {
                throw new IOException(
                          $"Custom type info {customTypeInfo} doesn't match expected type info {_type.TypeId}");
            }

            return(await ReadValueAsync(stream, reader, true).ConfigureAwait(false));
        }
예제 #16
0
        private static async Task <object[]> ReadArgumentsAsync(Stream stream, GraphBinaryReader reader)
        {
            var valuesLength = (int)await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            var values = new object[valuesLength];

            for (var i = 0; i < valuesLength; i++)
            {
                values[i] = await reader.ReadAsync(stream).ConfigureAwait(false);
            }
            return(values);
        }
예제 #17
0
        /// <inheritdoc />
        protected override async Task <TSet> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var length = (int)await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            var result = new TSet();

            for (var i = 0; i < length; i++)
            {
                result.Add((TMember)await reader.ReadAsync(stream).ConfigureAwait(false));
            }

            return(result);
        }
예제 #18
0
        protected override async Task <RelationIdentifier> ReadNonNullableValueAsync(Stream stream,
                                                                                     GraphBinaryReader reader)
        {
            var outVertexId = await stream.ReadLongAsync().ConfigureAwait(false);

            var typeId = await stream.ReadLongAsync().ConfigureAwait(false);

            var relationId = await stream.ReadLongAsync().ConfigureAwait(false);

            var inVertexId = await stream.ReadLongAsync().ConfigureAwait(false);

            return(new RelationIdentifier(outVertexId, typeId, relationId, inVertexId));
        }
예제 #19
0
        /// <inheritdoc />
        public async Task <object> ReadValueAsync(Stream stream, GraphBinaryReader reader, bool nullable)
        {
            if (nullable)
            {
                var valueFlag = await stream.ReadByteAsync().ConfigureAwait(false);

                if ((valueFlag & 1) == 1)
                {
                    return(null);
                }
            }

            return(await ReadValueAsync(stream, reader).ConfigureAwait(false));
        }
예제 #20
0
        /// <inheritdoc />
        protected override async Task <VertexProperty> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var vp = new VertexProperty(await reader.ReadAsync(stream).ConfigureAwait(false),
                                        (string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false),
                                        await reader.ReadAsync(stream).ConfigureAwait(false));

            // discard the parent vertex
            await reader.ReadAsync(stream).ConfigureAwait(false);

            // discard the properties
            await reader.ReadAsync(stream).ConfigureAwait(false);

            return(vp);
        }
예제 #21
0
        /// <inheritdoc />
        protected override async Task <Guid> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var bytes = new byte[16];

            // first 4 bytes in reverse order:
            bytes[3] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[2] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[1] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[0] = await stream.ReadByteAsync().ConfigureAwait(false);

            // 2 bytes in reverse order:
            bytes[5] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[4] = await stream.ReadByteAsync().ConfigureAwait(false);

            // 2 bytes in reverse order:
            bytes[7] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[6] = await stream.ReadByteAsync().ConfigureAwait(false);

            // 2 bytes:
            bytes[8] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[9] = await stream.ReadByteAsync().ConfigureAwait(false);

            // last 6 bytes:
            bytes[10] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[11] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[12] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[13] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[14] = await stream.ReadByteAsync().ConfigureAwait(false);

            bytes[15] = await stream.ReadByteAsync().ConfigureAwait(false);

            return(new Guid(bytes));
        }
예제 #22
0
        /// <inheritdoc />
        protected override async Task <Edge> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var id = await reader.ReadAsync(stream).ConfigureAwait(false);

            var label = (string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false);

            var inV = new Vertex(await reader.ReadAsync(stream).ConfigureAwait(false),
                                 (string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false));
            var outV = new Vertex(await reader.ReadAsync(stream).ConfigureAwait(false),
                                  (string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false));

            // discard possible parent vertex
            await reader.ReadAsync(stream).ConfigureAwait(false);

            // discard possible properties
            await reader.ReadAsync(stream).ConfigureAwait(false);

            return(new Edge(id, outV, label, inV));
        }
예제 #23
0
        /// <inheritdoc />
        protected override async Task <Path> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var readLabelObjects = (List <object>) await reader.ReadAsync(stream).ConfigureAwait(false);

            var labels = new List <ISet <string> >();

            foreach (var labelObjectList in readLabelObjects)
            {
                var labelSet = new HashSet <string>();
                foreach (var labelObj in (HashSet <object>)labelObjectList)
                {
                    labelSet.Add((string)labelObj);
                }
                labels.Add(labelSet);
            }

            var objects = (List <object>) await reader.ReadAsync(stream).ConfigureAwait(false);

            return(new Path(labels, objects));
        }
예제 #24
0
        /// <inheritdoc />
        protected override async Task <TList> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var length = (int)await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            var result = new TList();

            for (var i = 0; i < length; i++)
            {
                var value = await reader.ReadAsync(stream).ConfigureAwait(false);

                var bulk = (long)await reader.ReadValueAsync <long>(stream, false).ConfigureAwait(false);

                for (var j = 0; j < bulk; j++)
                {
                    result.Add(value);
                }
            }

            return(result);
        }
예제 #25
0
        /// <inheritdoc />
        protected override async Task <Bytecode> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var result = new Bytecode();

            var stepsLength = (int)await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            for (var i = 0; i < stepsLength; i++)
            {
                result.AddStep((string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false),
                               await ReadArgumentsAsync(stream, reader).ConfigureAwait(false));
            }

            var sourcesLength = await stream.ReadIntAsync().ConfigureAwait(false);

            for (var i = 0; i < sourcesLength; i++)
            {
                result.AddSource((string)await reader.ReadValueAsync <string>(stream, false).ConfigureAwait(false),
                                 await ReadArgumentsAsync(stream, reader).ConfigureAwait(false));
            }

            return(result);
        }
예제 #26
0
 /// <inheritdoc />
 public async Task <object> ReadAsync(Stream stream, GraphBinaryReader reader)
 {
     return(await ReadValueAsync(stream, reader, true).ConfigureAwait(false));
 }
예제 #27
0
 /// <summary>
 /// Reads a non-nullable value according to the type format.
 /// </summary>
 /// <param name="stream">The GraphBinary data to parse.</param>
 /// <param name="reader">A <see cref="GraphBinaryReader"/>.</param>
 /// <returns>The read value.</returns>
 protected abstract Task <T> ReadValueAsync(Stream stream, GraphBinaryReader reader);
예제 #28
0
 /// <inheritdoc />
 protected override async Task <T> ReadValueAsync(Stream stream, GraphBinaryReader reader)
 {
     return(await _readFunc.Invoke(stream).ConfigureAwait(false));
 }
예제 #29
0
        /// <inheritdoc />
        protected override async Task <TEnum> ReadValueAsync(Stream stream, GraphBinaryReader reader)
        {
            var enumValue = (string)await reader.ReadAsync(stream).ConfigureAwait(false);

            return(_readFunc.Invoke(enumValue));
        }
예제 #30
0
 /// <summary>
 /// Currently not supported.
 /// </summary>
 protected override Task <AbstractTraversalStrategy> ReadValueAsync(Stream stream, GraphBinaryReader reader)
 {
     throw new NotImplementedException("Reading a TraversalStrategy is not supported");
 }