示例#1
0
        /** Serialize metadata about all graphs */
        byte[] SerializeMeta()
        {
            if (graphs == null)
            {
                throw new System.Exception("No call to SerializeGraphs has been done");
            }

            meta.version   = new System.Version(4, 1, 16);
            meta.graphs    = graphs.Length;
            meta.guids     = new List <string>();
            meta.typeNames = new List <string>();

            // For each graph, save the guid
            // of the graph and the type of it
            for (int i = 0; i < graphs.Length; i++)
            {
                if (graphs[i] != null)
                {
                    meta.guids.Add(graphs[i].guid.ToString());
                    meta.typeNames.Add(graphs[i].GetType().FullName);
                }
                else
                {
                    meta.guids.Add(null);
                    meta.typeNames.Add(null);
                }
            }

            // Grab a cached string builder to avoid allocations
            var output = GetStringBuilder();

            TinyJsonSerializer.Serialize(meta, output);
            return(encoding.GetBytes(output.ToString()));
        }
示例#2
0
        /** Serializes the graph settings to JSON and returns the data */
        public byte[] Serialize(NavGraph graph)
        {
            // Grab a cached string builder to avoid allocations
            var output = GetStringBuilder();

            TinyJsonSerializer.Serialize(graph, output);
            return(encoding.GetBytes(output.ToString()));
        }