Phrase-checked parts
PDL has built-in support for protocols that employ checksums or block-check characters.
phrase-check {method: method,
modulo: mod,
encoding: encoding,
store-in: field name } =
begin
body
end;
Phrase-checked part | Description |
---|---|
phrase-check
part |
Only one is permitted in a phrase definition, although it can be continued. |
phrase-check |
This continued phrase part is used to run a phrase check over disjoint phrase portions. |
method: |
This is required to specify how the phrase-check value is computed as a function of the characters in the phrase-check region. These identifiers are available to specify the
|
modulo: |
This applies an arithmetic modulo operation to the phrase-check value before it is passed to the encoder. If supplied, then use an integer constant for mod. |
encoding: |
This specifies how the phrase-check value is converted into a string that is placed in the data stream, or extracted from the data stream. It is a required keyword, and must specify a valid encoding choice. |
field name |
This must not name a field that is inside body . |
There is no conceptual upper bound on the phrase-check value. This implementation can only represent numbers up to about 500,000,000, and overflows at 2Mb of 0xFF’s.
This example shows a disjointed phrase-check region:
# <data>, <data>, CHECK=<5-byte checksum>
define phrase split-checksumed-msg;
phrase-check {store-in: chk,
method: add,
modulo: 65536,
encoding: ascii( width: 5 ) } =
begin
field line1 = variable-array(not(‘,’));
end;
‘,’;
phrase-check continue =
begin
field line2 = variable-array(not(‘,’));
end;
‘,’;
"CHECK=";
field chk = fixed-array(5,digit);
‘.’;
end phrase;
If this phrase is written with line1 that is bound to abc
and line2 that is bound to 123
, then
this transmits:
abc, 123, CHECK=00444
This is because the sum of the ASCII codes for a, b, c, 1, 2, and 3 is 444 decimal.