Beispiel #1
0
        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);
        }
Beispiel #2
0
        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());
        }