Skip to content
Ingvar Stepanyan edited this page Apr 10, 2014 · 5 revisions

Typesets normally are just object dictionaries of typeName => type pairs with types that can refer to each other and completely describe some data structure format:

{
  'jBinary.all': 'File',
  'jBinary.littleEndian': true,

  // declaring custom type by wrapping structure
  DynamicArray: jBinary.Template({
    setParams: function (itemType) {
      this.baseType = {
        // using built-in type
        length: 'uint16',
        // using complex built-in type with simple argument and argument from another field
        values: ['array', itemType, 'length']
      };
    },
    read: function () {
      return this.baseRead().values;
    },
    write: function (values) {
      this.baseWrite({
        length: values.length,
        values: values
      });
    }
  }),

  // declaring simple structure
  FileItem: {
    // using built-in type with argument
    name: ['string0', 256],
    // using another custom type with no arguments
    content: 'DynamicArray'
  },

  // aliasing FileItem[] as type of entire File
  File: ['array', 'FileItem']
}

As was shown above, typesets may also contain special config values that set some global options for entire typeset.

As for now, such options are:

  • jBinary.all - reference to general type that represents entire data; required for enabling user to read/write entire file at once using readAll/writeAll.
  • jBinary.mimeType - sets mime-type which should be used for saving data from this format.
  • jBinary.littleEndian - sets default endianness for this format.
Clone this wiki locally