Esempio n. 1
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(AbstractTraversalStrategy value, Stream stream,
                                                      GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(GremlinType.FromFqcn(value.Fqcn), stream, false).ConfigureAwait(false);

            await writer.WriteValueAsync(value.Configuration, stream, false).ConfigureAwait(false);
        }
Esempio n. 2
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(decimal value, Stream stream, GraphBinaryWriter writer)
        {
            var(unscaledValue, scale) = GetUnscaledValueAndScale(value);
            await writer.WriteValueAsync(scale, stream, false).ConfigureAwait(false);

            await writer.WriteValueAsync(unscaledValue, stream, false).ConfigureAwait(false);
        }
        public override async Task WriteValueAsync(object value, Stream stream, GraphBinaryWriter writer, bool nullable)
        {
            if (value == null)
            {
                if (!nullable)
                {
                    throw new IOException("Unexpected null value when nullable is false");
                }

                await writer.WriteValueFlagNullAsync(stream).ConfigureAwait(false);

                return;
            }

            if (nullable)
            {
                await writer.WriteValueFlagNoneAsync(stream).ConfigureAwait(false);
            }

            var samplePerson = (SamplePerson)value;
            var name         = samplePerson.Name;

            // value_length = name_byte_length + name_bytes + long
            await stream.WriteIntAsync(4 + Encoding.UTF8.GetBytes(name).Length + 8).ConfigureAwait(false);

            await writer.WriteValueAsync(name, stream, false).ConfigureAwait(false);

            await writer.WriteValueAsync(samplePerson.BirthDate, stream, false).ConfigureAwait(false);
        }
Esempio n. 4
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(ILambda value, Stream stream, GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(value.Language, stream, false).ConfigureAwait(false);

            await writer.WriteValueAsync(value.LambdaExpression, stream, false).ConfigureAwait(false);

            await writer.WriteValueAsync(value.Arguments, stream, false).ConfigureAwait(false);
        }
Esempio n. 5
0
        private static async Task WriteInstructionsAsync(IReadOnlyCollection <Instruction> instructions, Stream stream,
                                                         GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(instructions.Count, stream, false).ConfigureAwait(false);

            foreach (var instruction in instructions)
            {
                await writer.WriteValueAsync(instruction.OperatorName, stream, false).ConfigureAwait(false);
                await WriteArgumentsAsync(instruction.Arguments, stream, writer).ConfigureAwait(false);
            }
        }
Esempio n. 6
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(string value, Stream stream, GraphBinaryWriter writer)
        {
            var bytes = Encoding.UTF8.GetBytes(value);
            await writer.WriteValueAsync(bytes.Length, stream, false).ConfigureAwait(false);

            await stream.WriteAsync(bytes).ConfigureAwait(false);
        }
Esempio n. 7
0
        protected override async Task WriteNonNullableValueAsync(JanusGraphP value, Stream stream,
                                                                 GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(value.OperatorName, stream, false).ConfigureAwait(false);

            await writer.WriteAsync(value.Value, stream).ConfigureAwait(false);
        }
Esempio n. 8
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(BigInteger value, Stream stream, GraphBinaryWriter writer)
        {
            var bytes = value.ToByteArray().Reverse().ToArray();
            await writer.WriteValueAsync(bytes.Length, stream, false).ConfigureAwait(false);

            await stream.WriteAsync(bytes).ConfigureAwait(false);
        }
Esempio n. 9
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(Vertex value, Stream stream, GraphBinaryWriter writer)
        {
            await writer.WriteAsync(value.Id, stream).ConfigureAwait(false);

            await writer.WriteValueAsync(value.Label, stream, false).ConfigureAwait(false);

            await writer.WriteAsync(null, stream).ConfigureAwait(false);
        }
Esempio n. 10
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(TMember[] value, Stream stream, GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(value.Length, stream, false).ConfigureAwait(false);

            foreach (var item in value)
            {
                await writer.WriteAsync(item, stream).ConfigureAwait(false);
            }
        }
Esempio n. 11
0
        private static async Task WriteArgumentsAsync(object[] arguments, Stream stream, GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(arguments.Length, stream, false).ConfigureAwait(false);

            foreach (var value in arguments)
            {
                await writer.WriteAsync(value, stream).ConfigureAwait(false);
            }
        }
Esempio n. 12
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(Property value, Stream stream, GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(value.Key, stream, false).ConfigureAwait(false);

            await writer.WriteAsync(value.Value, stream).ConfigureAwait(false);

            // placeholder for the parent element
            await writer.WriteAsync(null, stream).ConfigureAwait(false);
        }
Esempio n. 13
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(IDictionary <TKey, TValue> value, Stream stream, GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(value.Count, stream, false).ConfigureAwait(false);

            foreach (var key in value.Keys)
            {
                await writer.WriteAsync(key, stream).ConfigureAwait(false);

                await writer.WriteAsync(value[key], stream).ConfigureAwait(false);
            }
        }
Esempio n. 14
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(Edge value, Stream stream, GraphBinaryWriter writer)
        {
            await writer.WriteAsync(value.Id, stream).ConfigureAwait(false);

            await writer.WriteValueAsync(value.Label, stream, false).ConfigureAwait(false);

            await writer.WriteAsync(value.InV.Id, stream).ConfigureAwait(false);

            await writer.WriteValueAsync(value.InV.Label, stream, false).ConfigureAwait(false);

            await writer.WriteAsync(value.OutV.Id, stream).ConfigureAwait(false);

            await writer.WriteValueAsync(value.OutV.Label, stream, false).ConfigureAwait(false);

            // Placeholder for the parent vertex
            await writer.WriteAsync(null, stream).ConfigureAwait(false);

            // placeholder for the properties
            await writer.WriteAsync(null, stream).ConfigureAwait(false);
        }
Esempio n. 15
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(TSet value, Stream stream, GraphBinaryWriter writer)
        {
            var enumerable = (IEnumerable)value;
            var list       = enumerable.Cast <object>().ToList();

            await writer.WriteValueAsync(list.Count, stream, false).ConfigureAwait(false);

            foreach (var item in list)
            {
                await writer.WriteAsync(item, stream).ConfigureAwait(false);
            }
        }
Esempio n. 16
0
 /// <inheritdoc />
 protected override async Task WriteValueAsync(Type value, Stream stream, GraphBinaryWriter writer)
 {
     if (typeof(AbstractTraversalStrategy).IsAssignableFrom(value))
     {
         var strategyInstance = (AbstractTraversalStrategy)Activator.CreateInstance(value);
         await writer.WriteValueAsync(strategyInstance.Fqcn, stream, false).ConfigureAwait(false);
     }
     else
     {
         throw new IOException("Currently, writing of Types is only supported for traversal strategies.");
     }
 }
Esempio n. 17
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(P value, Stream stream, GraphBinaryWriter writer)
        {
            ICollection args = value.Value is ICollection ? value.Value : new List <object> {
                value.Value
            };

            var argsLength = value.Other == null ? args.Count : args.Count + 1;

            await writer.WriteValueAsync(value.OperatorName, stream, false).ConfigureAwait(false);

            await writer.WriteValueAsync(argsLength, stream, false).ConfigureAwait(false);

            foreach (var arg in args)
            {
                await writer.WriteAsync(arg, stream).ConfigureAwait(false);
            }

            if (value.Other != null)
            {
                await writer.WriteAsync(value.Other, stream).ConfigureAwait(false);
            }
        }
Esempio n. 18
0
 /// <inheritdoc />
 protected override async Task WriteValueAsync(GremlinType value, Stream stream, GraphBinaryWriter writer)
 {
     await writer.WriteValueAsync(value.Fqcn, stream, false).ConfigureAwait(false);
 }
Esempio n. 19
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(Traverser value, Stream stream, GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(value.Bulk, stream, false).ConfigureAwait(false);

            await writer.WriteAsync(value.Object, stream).ConfigureAwait(false);
        }
Esempio n. 20
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(byte[] value, Stream stream, GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(value.Length, stream, false).ConfigureAwait(false);

            await stream.WriteAsync(value, 0, value.Length).ConfigureAwait(false);
        }
Esempio n. 21
0
        /// <inheritdoc />
        protected override async Task WriteValueAsync(Binding value, Stream stream, GraphBinaryWriter writer)
        {
            await writer.WriteValueAsync(value.Key, stream, false).ConfigureAwait(false);

            await writer.WriteAsync(value.Value, stream).ConfigureAwait(false);
        }
Esempio n. 22
0
 /// <inheritdoc />
 protected override async Task WriteValueAsync(ITraversal value, Stream stream, GraphBinaryWriter writer)
 {
     await writer.WriteValueAsync(value.Bytecode, stream, false).ConfigureAwait(false);
 }