public byte[] Serialize(NavGraph graph) { MemoryStream memoryStream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(memoryStream); GraphSerializationContext ctx = new GraphSerializationContext(writer); graph.SerializeSettings(ctx); return(memoryStream.ToArray()); }
/** Serializes the graph settings to JSON and returns the data */ public byte[] Serialize(NavGraph graph) { #if !ASTAR_NO_JSON System.Text.StringBuilder output = GetStringBuilder(); //new System.Text.StringBuilder(); JsonWriter writer = new JsonWriter(output, writerSettings); writer.Write(graph); return(encoding.GetBytes(output.ToString())); #else var mem = new System.IO.MemoryStream(); var writer = new System.IO.BinaryWriter(mem); var ctx = new GraphSerializationContext(writer); graph.SerializeSettings(ctx); return(mem.ToArray()); #endif }
/** Serializes the graph settings to JSON and returns the data */ public byte[] Serialize(NavGraph graph) { #if !ASTAR_NO_JSON Debug.LogError("SerializeGraph"); // Grab a cached string builder to avoid allocations var output = GetStringBuilder(); var writer = new JsonWriter(output, writerSettings); writer.Write(graph); return(encoding.GetBytes(output.ToString())); #else var mem = new System.IO.MemoryStream(); var writer = new System.IO.BinaryWriter(mem); var ctx = new GraphSerializationContext(writer); graph.SerializeSettings(ctx); return(mem.ToArray()); #endif }
/** Serializes the graph settings to JSON and returns the data */ public byte[] Serialize (NavGraph graph) { #if !ASTAR_NO_JSON var output = GetStringBuilder ();//new System.Text.StringBuilder(); var writer = new JsonWriter (output,writerSettings); writer.Write (graph); return encoding.GetBytes (output.ToString()); #else var mem = new System.IO.MemoryStream(); var writer = new System.IO.BinaryWriter(mem); var ctx = new GraphSerializationContext (writer); graph.SerializeSettings (ctx); return mem.ToArray(); #endif }