The following are the possibilities for sharing data. Your situation will fall into one of these categories. Note that you may mix these types in the same data object if you are careful to keep your member data straight.
-
Sharing data between two fields in the same layer.
You can probably simply use a FIELD to hold the value and not use a data object at all. For instance, if the first field in a decode is a type indicator, later on in the layer you can refer to that field to figure out how to interpret the data. Using the STORE keyword allows you to save whatever data you need in a FIELD.
-
Sharing data between two layers in the same frame.
Sometimes a layer needs to know what a value was in a previously encountered layer in the current frame. For instance, if ABC protocol contains a "frame type" field, and XYZ protocol, which is farther along in the stack, needs the value of that field to know how to decode itself, the ABC layer needs to save the "frame type" for the XYZ layer. In most cases you can simply use the standard methods StoreIntraframeField and IntraframeField to share data between two layers of the same frame. But if the data is complex enough you'll need to use a data object. However, since all the information is present in the current frame, it can be reconstructed without any outside help. Therefore, the data object you create would not need the PUT_DATA_INTO_A_BYTE_ARRAY, OPTIMIZE_DATA, and GET_DATA_FROM_A_BYTE_ ARRAY sections since nothing needs to be saved during compilation and retrieved during reconstruction.
-
Sharing data between two frames.
This is the more complicated case. Sometimes one frame contains a command type, and, when decoding the response frame, you need to know what kind of command was sent because the response frame has a different format. In most cases you can use the standard methods StorePersistentField and PersistentField to share data between two frames. But if you have special needs you need a data object and you need to save the data between frames during compilation with PUT_DATA_INTO_A_BYTE_ARRAY (and possibly OPTIMIZE_DATA) and retrieve that data during reconstruction with GET_DATA_FROM_A_BYTE_ARRAY. See section Using Decoder Data Objects for per-Frame Data later in this chapter for details.