-
Notifications
You must be signed in to change notification settings - Fork 201
Enum description
Mikhail Yakshin edited this page Jul 21, 2016
·
3 revisions
Enum description allows to set up a enum (or closest equivalent) construct in target language source file, which can then be referenced in attribute descriptions using enum specification.
A given class can have multiple named enums, each of which is essentially a map from integers to strings. For example:
enums:
ip_protocol:
1: icmp
6: tcp
0x11: udp
port:
22: ssh
25: smtp
80: http
This one defines 2 named enums (named ip_protocol
and port
respectively), which can be referenced in attributes like that:
seq:
- id: src_port
type: u2
enum: port
Enum-mapped fields can be also used in expressions. One can compare it to enum constants, referencing it using enum_name::
enum_string syntax:
seq:
- id: http_version
type: u1
if: src_port == port::http
or one can convert them back into an integer, for example:
seq:
- id: field_for_privileged_port
type: u1
if: src_port.to_i < 1024