Changes between Version 17 and Version 18 of StructuredBinaryData


Ignore:
Timestamp:
2012-08-04T18:03:30Z (12 years ago)
Author:
Sean Bartell
Comment:

Document flow control syntax

Legend:

Unmodified
Added
Removed
Modified
  • StructuredBinaryData

    v17 v18  
    132132
    133133||= name =||= input =||= output =||= description =||= example =||
    134 ||ascii           ||blob node        ||string       ||decodes some bytes as ASCII characters ||  `hex:6869` becomes `"hi"` ||
    135 ||uint8           ||1‐byte blob node ||integer node ||decodes a 1‐byte unsigned integer ||  `hex:11` becomes `17` ||
    136 ||uint16be        ||2‐byte blob node ||integer node ||decodes a 2‐byte big‐endian unsigned integer ||  `hex:0201` becomes `513` ||
    137 ||uint16le        ||2‐byte blob node ||integer node ||decodes a 2‐byte little‐endian unsigned integer ||  `hex:0101` becomes `257` ||
    138 ||uint32be        ||4‐byte blob node ||integer node ||decodes a 4‐byte big‐endian unsigned integer ||  `hex:00000201` becomes `513` ||
    139 ||uint32le        ||4‐byte blob node ||integer node ||decodes a 4‐byte little‐endian unsigned integer ||  `hex:01010000` becomes `257` ||
    140 ||uint64be        ||8‐byte blob node ||integer node ||decodes a 8‐byte big‐endian unsigned integer ||  `hex:0000000000000201` becomes `513` ||
    141 ||uint64le        ||8‐byte blob node ||integer node ||decodes a 8‐byte little‐endian unsigned integer ||  `hex:0101000000000000` becomes `257` ||
    142 ||zero_terminated ||blob node        ||blob node    ||takes bytes up until the first `00` ||  `hex:7f0400` becomes `hex:7f04` ||
     134||ascii             ||blob node        ||string       ||decodes some bytes as ASCII characters ||  `hex:6869` becomes `"hi"` ||
     135||known_length(len) ||blob node        ||blob node    ||requires the input to have a known length || ||
     136||nonzero_boolean   ||integer          ||boolean      ||decodes a boolean where nonzero values are true || `0` becomes `false` ||
     137||uint8             ||1‐byte blob node ||integer node ||decodes a 1‐byte unsigned integer ||  `hex:11` becomes `17` ||
     138||uint16be          ||2‐byte blob node ||integer node ||decodes a 2‐byte big‐endian unsigned integer ||  `hex:0201` becomes `513` ||
     139||uint16le          ||2‐byte blob node ||integer node ||decodes a 2‐byte little‐endian unsigned integer ||  `hex:0101` becomes `257` ||
     140||uint32be          ||4‐byte blob node ||integer node ||decodes a 4‐byte big‐endian unsigned integer ||  `hex:00000201` becomes `513` ||
     141||uint32le          ||4‐byte blob node ||integer node ||decodes a 4‐byte little‐endian unsigned integer ||  `hex:01010000` becomes `257` ||
     142||uint64be          ||8‐byte blob node ||integer node ||decodes a 8‐byte big‐endian unsigned integer ||  `hex:0000000000000201` becomes `513` ||
     143||uint64le          ||8‐byte blob node ||integer node ||decodes a 8‐byte little‐endian unsigned integer ||  `hex:0101000000000000` becomes `257` ||
     144||zero_terminated   ||blob node        ||blob node    ||takes bytes up until the first `00` ||  `hex:7f0400` becomes `hex:7f04` ||
    143145
    144146== Basic syntax ==
     
    207209is `{"id": 6, "label": "A", "x": 3, "y": 8}`.
    208210
     211== Flow Control ==
     212
     213Boolean conditions can use
     214`if (expression) { transform-if-true } else { transform-if-false }`, for
     215example: `if (little_endian) { uint32le } else { uint32be }`. There is also
     216syntax for switches: `switch (expression) { expression: transform; ... }`. Both
     217of these have syntactic sugar for use in `struct`s; in a `struct`,
     218`if (expression) { fields... }` is equivalent to
     219`<- if (expression) { struct { fields... } };`.
     220
     221Three kinds of repetition are supported. `repeat(expression) {transform}`
     222applies the transform a given number of times. `repeat {transform}` applies the
     223transform until it fails or the end of the data is reached.
     224`do {transform} while(expression)` applies the transform until the expression,
     225evaluated within the result of the transform, is false; this can be used for
     226things like
     227`do { struct { .keep_going <- nonzero_boolean <- uint8; .val <- uint8; } } while(.keep_going)`.
     228For each type of repetition, the result is an internal node with sequential
     229keys starting at `0`.
     230
    209231== Using Bithenge ==
    210232
     
    242264=== Other ideas ===
    243265
    244  Conditional transforms:: A way to apply different transforms depending on an
    245    expression. For example, something like:
    246    `if (.has_extra) { struct { .extra <- uint32le; } }`.
    247  Repetition:: Transforms may need to be repeated a known number of times, until
    248    the end of the data, or until the transform indicates that repetition should
    249    stop. For instance, `repeat(.len) {uint32le;}`. The result could be a tree
    250    like `{0: 1351, 1: 17}`.
    251266 Subblobs:: When there are pointers to other offsets in the blob, the script
    252267   could pass the whole blob as a parameter and apply transforms to subblobs.