Length-encoded phrase parts

The programmable driver supports length-encoding of line phrases.

The syntax is similar to that for phrase checks:

length-encoded {encoding: encoding,
store-in: field-name } =
begin
body
end;

The READ semantics are that the phrase part matches if the body matches, where:

  • The choices for encoding are the same as those for the phrase-check phrase part.
  • field-name indicates the body length, in bytes.

    If the body contains a variable-array (any) subpart, then the variable-array’s actual length is the length stored in field-name less the length of all the body’s fixed-length parts.

    When writing a command, reverse computation happens. The field-name is completed with the actual length of the field text with a structure of variable-array (any) structure plus the length of all the body’s fixed-length parts.

  • For these operations to make sense, the body can contain only zero or one variable-array (any). All other fields inside body must be a fixed length.

    In particular, if field-name happens inside of body, then it must use a fixed encoding. The compiler verifies that these conditions hold.

For example, in a typical 2-byte length-encoded phrase that is used on a TCP connection:

# <2-byte length data>
define phrase blob-data;
length-encoded {encoding: network( bytes: 2 ), 
store-in: len } = 
begin
field len = fixed-array(2,any);
field blob = variable-array(any);
end;