Examples of Non-Automatic Maps(4.0)
Non-automatic maps provide explicit mapping between the external and internal format. Such mappings work on fields with primitive types and/or fields that are instances of other formats. In the latter case, the maps can be nested indefinitely. The following two examples demonstrate these concepts.
Example - Non-Automatic Maps, all primitives
In the following example a decoder, based on the in_map
, will do the following:
Read an instance of the external record
ExtFormat
.Associate
ef1
withif1
, that is, any reference toif1
will force decoding of the information ofef1
and in the process convert it to an integer.Associate
ef2
withif2
, that is, any reference toif2
will force decoding of the information ofef2
and in the process convert it to a string.
external ExtFormat { ascii ef1 : static_size(4), padded_with(" "); int ef2 : static_size(2); }; internal IntFormat { int if1; ascii if2; }; in_map InMapFormat: external(ExtFormat), internal(IntFormat) { e:ef1 and i:if1; e:ef2 and i:if2; };
Example - Non-Automatic Maps, externals in externals
In the following example a decoder, based on the in_map
, will do the following:
Read an instance of the external record
ExtFormat2
.Associate
ef1
withif1
, that is, any reference toif1
will force decoding of the information ofef1
. The conversion betweenExtFormat1
andIntFormat1
is, in this case, dictated by the in-map namedInMapFormat1
as declared inInMapFormat2.
external ExtFormat1 { ascii ef1 : static_size(4); }; external ExtFormat2 { ExtFormat1 ef1; }; internal IntFormat1 { int if1; }; internal IntFormat2 { IntFormat1 if1; }; in_map InMapFormat1: external(ExtFormat1), internal(IntFormat1) { e:ef1 and i:if1; }; in_map InMapFormat2: external(ExtFormat2), internal(IntFormat2) { e:ef1 and i:if1 using in_map InMapFormat1; };
As seen in the example, explicit map specifications for complex formats can become very large, even describing all the internals to map data too, can be a huge task. This is why automatic mapping is normally used.