TextSerializer Prototype

The serialized file format is pretty generic... each line (using any line separator, so we don't mind being moved between platforms) consists of a command name, and some parameters (optionally). The commands 'start' and 'end' mark the chunks of properties for each object - in this case motifs. Every command inside a start/end block is considered a property for the object. There are some rules, but we are generally pretty flexible.

Syntax

var object = new TextSerializer(file);

Arguments

ArgumentSummary
file

Remarks

Example file:
  START <Array>
    START 0
      "message" "Food%3a%20Mmm...%20food..."
    END
    START 1
      "message" "Busy%3a%20Working."
    END
    START 2
      "message" "Not%20here."
    END
  END

The whitespace at the start of the inner lines is generated by the serialisation process, but is ignored when parsing - it is only to make the file more readable.

The START command may be followed by one or both of a class name (enclosed in angle brackets, as above) and a property name (the first non-<>-enclosed word). Top-level START commands must not have a property name, although a class name is fine. Only the following class names are supported:
  - Object (the default)
  - Array

For arrays, there are some limitations; saving an array cannot save any properties that are not numerics, due to limitations in JS' for...in enumeration. Thus, for loading, only items with numeric property names are allowed. If an item is STARTed inside an array, and specifies no property name, it will be push()ed into the array instead.

Members

MemberSummary
close close()
deserialize deserialize()
open open(direction)
serialize serialize(object)

See Also

Source Code

function TextSerializer(file)
{
this._initialized = false;
if (typeof file == "string")
this._file = new nsLocalFile(file);
else
this._file = file;
this._open = false;
this._buffer = "";
this._lines = [];
this.lineEnd = "\n";
this._initialized = true;
}