private void ProcessMessage(IMessageResponseHandler responseHandler) { var message = _packStreamReader.Read(); if (message is RecordMessage record) { record.Dispatch(responseHandler); } else if (message is SuccessMessage success) { success.Dispatch(responseHandler); } else if (message is FailureMessage failure) { failure.Dispatch(responseHandler); } else if (message is IgnoredMessage ignored) { ignored.Dispatch(responseHandler); } else { throw new ProtocolException("Unknown response message type: " + message.GetType().FullName); } }
public object Read(IPackStreamReader reader, byte signature, long size) { var values = new List <object>(); for (var i = 0; i < size; i++) { values.Add(reader.Read()); } return(new StructType(values)); }
public override object Deserialize(IPackStreamReader reader, byte signature, 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)); }
private void ProcessMessage(IMessageResponseHandler responseHandler) { var message = _packStreamReader.Read(); if (message is IResponseMessage response) { response.Dispatch(responseHandler); } else { throw new ProtocolException($"Unknown response message type {message.GetType().FullName}"); } }
public override object Read(IPackStreamReader reader, byte signature, 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)); }
public override object Read(IPackStreamReader reader, byte signature, 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())); }