public static byte[] Write(ProcNode node) { ByteBuffer bfs = VisualNode.Write(node); bfs.WriteBytes(FieldNode.Write(node.resultField)); return(bfs.Getbuffer()); }
public static ProcNode Read(byte[] bytes) { ProcNode node = new ProcNode(); ByteBuffer bfs = new ByteBuffer(bytes); VisualNode.Read(bfs, node); node.resultField = FieldNode.Read(bfs.ReadBytes()); node.resultField.Target = node; return(node); }
public static VisualGraphData Read(byte[] bytes) { VisualGraphData data = new VisualGraphData(); ByteBuffer bfs = new ByteBuffer(bytes); int count = bfs.ReadInt32(); for (int i = 0; i < count; ++i) { VisualNode.NodeType type = (VisualNode.NodeType)bfs.ReadShort(); if (type == VisualNode.NodeType.SetVar) { data.AddNode(SetVarNode.Read(bfs.ReadBytes())); } else if (type == VisualNode.NodeType.GetVar) { data.AddNode(GetVarNode.Read(bfs.ReadBytes())); } else if (type == VisualNode.NodeType.Func) { data.AddNode(FuncNode.Read(bfs.ReadBytes())); } else if (type == VisualNode.NodeType.AddOp) { data.AddNode(AddOpNode.Read(bfs.ReadBytes(), new AddOpNode())); } else if (type == VisualNode.NodeType.MinusOp) { data.AddNode(MinusOpNode.Read(bfs.ReadBytes(), new MinusOpNode())); } else if (type == VisualNode.NodeType.MultiplyOp) { data.AddNode(MultiplyOpNode.Read(bfs.ReadBytes(), new MultiplyOpNode())); } else if (type == VisualNode.NodeType.DivisionOp) { data.AddNode(DivisionOpNode.Read(bfs.ReadBytes(), new DivisionOpNode())); } else if (type == VisualNode.NodeType.Proc) { data.AddNode(ProcNode.Read(bfs.ReadBytes())); } } return(data); }
public static byte[] Write(VisualGraphData data) { ByteBuffer bfs = new ByteBuffer(); bfs.WriteInt32(data.Nodes.Count); for (int i = 0; i < data.Nodes.Count; ++i) { var d = data.Nodes[i]; bfs.WriteShort((short)d.GetNodeType()); if (d.GetNodeType() == VisualNode.NodeType.SetVar) { bfs.WriteBytes(SetVarNode.Write(d as SetVarNode)); } else if (d.GetNodeType() == VisualNode.NodeType.GetVar) { bfs.WriteBytes(GetVarNode.Write(d as GetVarNode)); } else if (d.GetNodeType() == VisualNode.NodeType.Func) { bfs.WriteBytes(FuncNode.Write(d as FuncNode)); } else if (d.GetNodeType() == VisualNode.NodeType.AddOp) { bfs.WriteBytes(AddOpNode.Write(d as AddOpNode)); } else if (d.GetNodeType() == VisualNode.NodeType.MinusOp) { bfs.WriteBytes(MinusOpNode.Write(d as MinusOpNode)); } else if (d.GetNodeType() == VisualNode.NodeType.MultiplyOp) { bfs.WriteBytes(MultiplyOpNode.Write(d as MultiplyOpNode)); } else if (d.GetNodeType() == VisualNode.NodeType.DivisionOp) { bfs.WriteBytes(DivisionOpNode.Write(d as DivisionOpNode)); } else if (d.GetNodeType() == VisualNode.NodeType.Proc) { bfs.WriteBytes(ProcNode.Write(d as ProcNode)); } } return(bfs.Getbuffer()); }