/// <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)); }
/// <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]; }
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)); }
/// <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())); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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); }
/// <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)); }
/// <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); }
/// <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); }
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)); }
/// <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)); }
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); }
/// <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); }
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)); }
/// <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)); }
/// <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); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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); }
/// <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); }
/// <inheritdoc /> public async Task <object> ReadAsync(Stream stream, GraphBinaryReader reader) { return(await ReadValueAsync(stream, reader, true).ConfigureAwait(false)); }
/// <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);
/// <inheritdoc /> protected override async Task <T> ReadValueAsync(Stream stream, GraphBinaryReader reader) { return(await _readFunc.Invoke(stream).ConfigureAwait(false)); }
/// <inheritdoc /> protected override async Task <TEnum> ReadValueAsync(Stream stream, GraphBinaryReader reader) { var enumValue = (string)await reader.ReadAsync(stream).ConfigureAwait(false); return(_readFunc.Invoke(enumValue)); }
/// <summary> /// Currently not supported. /// </summary> protected override Task <AbstractTraversalStrategy> ReadValueAsync(Stream stream, GraphBinaryReader reader) { throw new NotImplementedException("Reading a TraversalStrategy is not supported"); }