-
Notifications
You must be signed in to change notification settings - Fork 198
Attribute description
Mikhail Yakshin edited this page Mar 1, 2016
·
10 revisions
Attribute description specifies how to read one particular attribute — typically, a single number, a string, array of bytes, etc. Attribute can also reference other complex structures by specifying user type given in type description. Each attribute is typically compiled into equivalent parsing instruction(s) in target language.
- Contents: a string that matches
/^[a-z][a-z0-9_]*$/
— i.e. starts with lowercase letter and then may contain lowercase letters, numbers and underscore - Purpose: identify attribute among others
- Influences: used as variable / field name in target programming language
- Mandatory: yes
- Contents: one of primitive data types or a user-specified type name
- Purpose: define a data type for an attribute
- Influences: how much bytes would be read, data type and contents of a variable in target programming language
- Mandatory: no — if
type
is not specified, then attribute is considered a generic byte sequence
- Contents:
expr
oreos
- Purpose: designate repeated attribute in a structure;
- if
repeat: expr
is used, then attribute is repeated the number of times specified inrepeat-expr
key; - if
repeat: eos
is used, then attribute is repeated until the end of current stream
- if
- Influences: attribute would be read as array / list / sequence, executing parsing code multiple times
- Mandatory: no
- Contents: expression
- Purpose: specify number of repetitions for repeated attribute
- Influences: number of times attribute is parsed
- Mandatory: yes, if
repeat: expr
- Contents: expression
- Purpose: mark the attribute as optional
- Influences: attribute would be parsed only if condition specified in
if
key evaluates (in runtime) to true - Mandatory: no
If there's no type specified, attribute will be read just as a sequence of bytes from a stream. Thus, one has to decide on how many bytes to read? There are two ways:
- Specify amount of bytes to read in
size
key. One can specify an integer constant or an expression in this field (for example, if the number of bytes to read depends on some other attribute) - Set
size-eos: true
, thus ordering to read all the bytes till the end of current stream.