A* Pathfinding Project  3.8.5
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
AstarSerializer Class Reference

Handles low level serialization and deserialization of graph settings and data. More...

Detailed Description

Handles low level serialization and deserialization of graph settings and data.

Mostly for internal use. You can use the methods in the AstarData class for higher level serialization and deserialization.

See Also
AstarData

Public Member Functions

 AstarSerializer (AstarData data)
 
 AstarSerializer (AstarData data, SerializeSettings settings)
 
void CloseDeserialize ()
 
byte[] CloseSerialize ()
 
void DeserializeEditorSettings (GraphEditorBase[] graphEditors)
 Deserializes graph editor settings.
 
void DeserializeExtraInfo ()
 Deserializes extra graph info.
 
NavGraph[] DeserializeGraphs ()
 Deserializes graph settings.
 
uint GetChecksum ()
 
bool OpenDeserialize (byte[] bytes)
 
void OpenSerialize ()
 
void PostDeserialization ()
 Calls PostDeserialization on all loaded graphs.
 
byte[] Serialize (NavGraph graph)
 Serializes the graph settings to JSON and returns the data.
 
void SerializeEditorSettings (GraphEditorBase[] editors)
 
void SerializeExtraInfo ()
 
void SerializeGraphs (NavGraph[] _graphs)
 
void SerializeNodes ()
 Deprecated method to serialize node data.
 
void SetGraphIndexOffset (int offset)
 

Static Public Member Functions

static byte[] LoadFromFile (string path)
 Load the specified data from the specified path.
 
static void SaveToFile (string path, byte[] data)
 Save the specified data at the specified path.
 

Private Member Functions

void AddChecksum (byte[] bytes)
 
bool AnyDestroyedNodesInGraphs ()
 
GraphMeta DeserializeBinaryMeta (ZipEntry entry)
 
bool DeserializeExtraInfo (NavGraph graph)
 
NavGraph DeserializeGraph (int zipIndex, int graphIndex)
 
GraphMeta DeserializeMeta (ZipEntry entry)
 
void DeserializeNodeLinks (GraphNode[] int2Node)
 
GraphNode[] DeserializeNodeReferenceMap ()
 
void DeserializeNodeReferences (NavGraph graph, GraphNode[] int2Node)
 
byte[] SerializeMeta ()
 Serialize metadata about all graphs.
 
byte[] SerializeNodeLinks ()
 

Static Private Member Functions

static void CloseOrDispose (BinaryWriter writer)
 
static System.Version FullyDefinedVersion (System.Version v)
 Returns a version with all fields fully defined.
 
static BinaryReader GetBinaryReader (ZipEntry entry)
 Returns a binary reader for the data in the zip entry.
 
static int GetMaxNodeIndexInAllGraphs (NavGraph[] graphs)
 
static string GetString (ZipEntry entry)
 Returns the data in the zip entry as a string.
 
static System.Text.StringBuilder GetStringBuilder ()
 Returns a cached StringBuilder.
 
static byte[] SerializeGraphExtraInfo (NavGraph graph)
 Serializes info returned by NavGraph.SerializeExtraInfo.
 
static byte[] SerializeGraphNodeReferences (NavGraph graph)
 Used to serialize references to other nodes e.g connections.
 
static byte[] SerializeNodeIndices (NavGraph[] graphs)
 

Private Attributes

const string binaryExt = ".binary"
 Extension to use for binary files.
 
uint checksum = 0xffffffff
 Checksum for the serialized data.
 
AstarData data
 
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding()
 
Dictionary< NavGraph, int > graphIndexInZip
 Index used for the graph in the file.
 
int graphIndexOffset
 
NavGraph[] graphs
 Graphs that are being serialized or deserialized.
 
const string jsonExt = ".json"
 Extension to use for json files.
 
GraphMeta meta
 Graph metadata.
 
SerializeSettings settings
 Settings for serialization.
 
ZipFile zip
 Zip which the data is loaded from.
 
MemoryStream zipStream
 Memory stream with the zip data.
 

Static Private Attributes

static System.Text.StringBuilder _stringBuilder = new System.Text.StringBuilder()
 Cached StringBuilder to avoid excessive allocations.
 

Constructor & Destructor Documentation

AstarSerializer ( AstarData  data,
SerializeSettings  settings 
)

Member Function Documentation

void AddChecksum ( byte[]  bytes)
private
bool AnyDestroyedNodesInGraphs ( )
private
void CloseDeserialize ( )
static void CloseOrDispose ( BinaryWriter  writer)
staticprivate
byte [] CloseSerialize ( )
GraphMeta DeserializeBinaryMeta ( ZipEntry  entry)
private
void DeserializeEditorSettings ( GraphEditorBase[]  graphEditors)

Deserializes graph editor settings.

For future compatibility this method does not assume that the graphEditors array matches the graphs array in order and/or count. It searches for a matching graph (matching if graphEditor.target == graph) for every graph editor. Multiple graph editors should not refer to the same graph.

Note
Stored in files named "graph#_editor.json" where # is the graph number.
bool DeserializeExtraInfo ( NavGraph  graph)
private
void DeserializeExtraInfo ( )

Deserializes extra graph info.

Extra graph info is specified by the graph types.

See Also
Pathfinding.NavGraph.DeserializeExtraInfo
Note
Stored in files named "graph#_extra.binary" where # is the graph number.
NavGraph DeserializeGraph ( int  zipIndex,
int  graphIndex 
)
private
NavGraph [] DeserializeGraphs ( )

Deserializes graph settings.

Note
Stored in files named "graph#.json" where # is the graph number.
GraphMeta DeserializeMeta ( ZipEntry  entry)
private
void DeserializeNodeLinks ( GraphNode[]  int2Node)
private
GraphNode [] DeserializeNodeReferenceMap ( )
private
void DeserializeNodeReferences ( NavGraph  graph,
GraphNode[]  int2Node 
)
private
static System.Version FullyDefinedVersion ( System.Version  v)
staticprivate

Returns a version with all fields fully defined.

This is used because by default new Version(3,0,0) > new Version(3,0). This is not the desired behaviour so we make sure that all fields are defined here

static BinaryReader GetBinaryReader ( ZipEntry  entry)
staticprivate

Returns a binary reader for the data in the zip entry.

uint GetChecksum ( )
static int GetMaxNodeIndexInAllGraphs ( NavGraph[]  graphs)
staticprivate
static string GetString ( ZipEntry  entry)
staticprivate

Returns the data in the zip entry as a string.

static System.Text.StringBuilder GetStringBuilder ( )
staticprivate

Returns a cached StringBuilder.

This function only has one string builder cached and should thus only be called from a single thread and should not be called while using an earlier got string builder.

static byte [] LoadFromFile ( string  path)
static

Load the specified data from the specified path.

bool OpenDeserialize ( byte[]  bytes)
void OpenSerialize ( )
void PostDeserialization ( )

Calls PostDeserialization on all loaded graphs.

static void SaveToFile ( string  path,
byte[]  data 
)
static

Save the specified data at the specified path.

byte [] Serialize ( NavGraph  graph)

Serializes the graph settings to JSON and returns the data.

void SerializeEditorSettings ( GraphEditorBase[]  editors)
void SerializeExtraInfo ( )
static byte [] SerializeGraphExtraInfo ( NavGraph  graph)
staticprivate

Serializes info returned by NavGraph.SerializeExtraInfo.

static byte [] SerializeGraphNodeReferences ( NavGraph  graph)
staticprivate

Used to serialize references to other nodes e.g connections.

Nodes use the GraphSerializationContext.GetNodeIdentifier and GraphSerializationContext.GetNodeFromIdentifier methods for serialization and deserialization respectively.

void SerializeGraphs ( NavGraph[]  _graphs)
byte [] SerializeMeta ( )
private

Serialize metadata about all graphs.

static byte [] SerializeNodeIndices ( NavGraph[]  graphs)
staticprivate
byte [] SerializeNodeLinks ( )
private
void SerializeNodes ( )

Deprecated method to serialize node data.

Deprecated:
Not used anymore
void SetGraphIndexOffset ( int  offset)

Member Data Documentation

System.Text.StringBuilder _stringBuilder = new System.Text.StringBuilder()
staticprivate

Cached StringBuilder to avoid excessive allocations.

const string binaryExt = ".binary"
private

Extension to use for binary files.

uint checksum = 0xffffffff
private

Checksum for the serialized data.

Used to provide a quick equality check in editor code

AstarData data
private
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding()
private
Dictionary<NavGraph, int> graphIndexInZip
private

Index used for the graph in the file.

If some graphs were null in the file then graphIndexInZip[graphs[i]] may not equal i. Used for deserialization.

int graphIndexOffset
private
NavGraph [] graphs
private

Graphs that are being serialized or deserialized.

const string jsonExt = ".json"
private

Extension to use for json files.

GraphMeta meta
private

Graph metadata.

SerializeSettings settings
private

Settings for serialization.

ZipFile zip
private

Zip which the data is loaded from.

MemoryStream zipStream
private

Memory stream with the zip data.


The documentation for this class was generated from the following file: