A Sequential Format Example

The example illustrated in this appendix is a format definition for decoding a shortened version of EWSD AMA (Automatic Message Accounting).

All incoming records are of the same record type, however their content varies. The first four fields are present in all records, the fifth field varies depending on the content of the field RecordOwnerTypePresent. The last three fields are optional.

A schematic representation of the example discussed in this section

external

Since the last three optional fields (including  RecordOwnerType and RecordOwnerDN) consist of several fields, each one is defined as its own type. That is, an external sequential format.



Note!

The FillerRecord_0x00_EXT construct. This is the padding which may be present between records. Hence, it is defined as a record type identified by the decoder, however not routed on to the subsequent agent (see the in_map definitions).

If the format is only used for decoding (which is the normal case for switch output formats), the encoding instructions (encode_value) in the following code is skipped.

external AMARecord_EXT: identified_by(RecordIdentifier == 0x84), dynamic_size(RecordLength) { int(little_endian) RecordIdentifier :static_size(1), external_only, encode_value(0x84); int(little_endian) RecordLength :static_size(2), external_only, encode_value(udr_size);

This byte contains several flags, from which only one is of interest. Therefore, if RecordOwnerTypePresent is set, then the RecordOwnerType is present, or else the RecordOwnerDN data is. See the presence specifications in the following code.

bit_block :static_size(1) { int(little_endian) RecordOwnerTypePresent: msb(7),lsb(7), external_only, encode_value( (field_present(RecordOwnerType)?1:0)); };

Since three bytes of unwanted data is present, it is specified as external_only to stop the field from getting automatically generated in the target internal. No encoding is specified (0 padding is used).

byte ignoredFields: static_size(3), external_only;

Either RecordOwnerType or RecordOwnerDN is present. To encode them, it is important to note that exactly one of these fields must be present in the output data.

The rest of the record consists of optional packages with additional information. The full AMA format contains lots of other packages (and additional information in the header), however in this example, only three packages are included. Any unrecognized package leads to failure of the decoding, since the size of the set is specified (all the remaining data must be handled by the set decoding).

The following is a typical construction for BCD data with a nibble length specification. Both nibble size (native_size) and field size (dynamic_size) must be specified.



Note!

The identified_by expression, which must be specified for any format used in a set construct.



Alternative Syntax

An alternative to use the set construct, in the external definition for AMARecord_ext, switched_set could be used. This impacts the syntax for the Package_*_EXT types. Only the syntax differing from the original example is shown. The main reason for using switched_set instead of set is when performance must be increased.

The following is a typical construction for BCD data with a nibble length specification. Both nibble size (native_size) and field size (dynamic_size) must be specified.



Note!

No  identified_by  or PackageNumber is present, since this is handled in the containing  switched_set .

internal

No internal is used. In this case, the target_internal is sufficient; all field names and field types are in order and there is only one type of record present in the input, and no additional fields are required.

in_map

The padding in the records is recognized by the decoder, however it is not actually mapped in to the system due to the use of the discard_output flag.

The AMARecord_Map contains sub-automatic specifications (the target_internal specifications within the automatic block), which give five additional internal formats (other than the AMARecord). This is useful when you want to route them as individual records.

decoder

The padding pseudo-records and data records can arrive in any order, therefore there is no need to define a constructed decoder.