public void WritePssg(Stream fileStream) { using (PssgBinaryWriter writer = new PssgBinaryWriter(EndianBitConverter.Big, fileStream, true)) { writer.Write(Encoding.ASCII.GetBytes("PSSG")); writer.Write(0); // Length, filled in later if (RootNode != null) { // make all ids -1 PssgSchema.ClearSchemaIds(); // Get the counts, and update ids of the nodes/attributes used in this file GetNodeAttributeNameCount(this, out var nodeNameCount, out var attributeNameCount); writer.Write(attributeNameCount); writer.Write(nodeNameCount); // Update ids again to make sequential and save ones used in this file PssgSchema.SaveToPssg(writer); RootNode.UpdateSize(); RootNode.Write(writer); } writer.BaseStream.Position = 4; writer.Write((int)writer.BaseStream.Length - 8); }
public void WritePssg(Stream fileStream, bool close) { PssgBinaryWriter writer = new PssgBinaryWriter(new BigEndianBitConverter(), fileStream); try { writer.Write(Encoding.ASCII.GetBytes("PSSG")); writer.Write(0); // Length, filled in later if (RootNode != null) { int nodeNameCount = 0; int attributeNameCount = 0; PssgSchema.ClearSchemaIds(); // make all ids -1 RootNode.UpdateId(ref nodeNameCount, ref attributeNameCount); writer.Write(attributeNameCount); writer.Write(nodeNameCount); PssgSchema.SaveToPssg(writer); // Update Ids again, to make sequential RootNode.UpdateSize(); RootNode.Write(writer); } writer.BaseStream.Position = 4; writer.Write((int)writer.BaseStream.Length - 8); if (close) { writer.Close(); } } catch (Exception ex) { if (writer != null) { writer.Close(); } throw ex; } }