Formatter decorator follows the DECORATOR design pattern. You can add decorators for each format element. The decorator needs to be defined right after the format element. Every Format Decorator is a subclass of com.ibm.btt.format.BaseDecorator.
<format.xml> <format id="PersonFormat"> <record> <fString dataName="name" encoding="cp937"/> <selfLength/> <fInteger dataName="age" byteOrdering="host"/> <selfLength/> </record> </format> </format.xml>Where, selfLength is a decorator. The first selfLength is decorator for fString. The second selfLenght is decorator for fInteger.
Decorator is used modify the binary message formatted by decorated format element and modify the binary message before the decorated format element unformat it.
Class | Attributes | Sample definition |
---|---|---|
HexDelimiter (Add a delimiter after the binary message) |
hexDelimCharStr: a String that represents an array of hex values. |
<fInteger dataName="dInt" size="int" byteOrdering="pc"/> <hexDelim hexDelimCharStr="DDDD" /> For example, if you format an integer value of -1024 with this format element, you will get the binary message: 00FCFFFFDDDD (hex value). |
FiexedLength (Adjusts a formatted binary message to a fixed length by either truncating it or by padding and justifying it) |
length: an int value that indicates the length of the binary message. default value is: 0. padByte:a byte in hex value representation. default value is: 00. alignment:optional values are: left, right. default value is: left |
<fString dataName="name" encoding="cp937"/> <fixedLength length="10" alignment="right"/> For example, if you format a String “George” with this format element, you will get the binary message: 00000000C78596998785 (hex value). If you format a String “George. Wilhelm. T” with this format element, you will get the binary message: C785969987854B40E689 (hex value). |
MaximumLength (Truncates the binary message if it is over the specified length. If the binary message is under the specified length, the decorator does not modify it) |
length: a int value that indicates the maximum length of the binary message. default value is: 0. |
<fString dataName="name" encoding="cp937"/> <maxLength length="10"/> For example, if you format a String “George. Wilhelm. T” with this format element, you will get the binary message: C785969987854B40E689 (hex value). |
NullCheckDecorator (Handles conversions between binary message and data field when either the binary message is empty or the data field is null) |
N/A | <fString dataName="name" encoding="cp937"/> <nullCheck/> For example, if you format a String which is null with this format element, you will get a binary message in 0 length. And if you unformat a binary message in 0 length, the format element will make no modification to the data field. |
SelfLength (Prefixes the length of the formatted binary message as an unsigned integer) |
size: the length of prefix. default value is 1. byteOrdering:the byte ordering of prefix. optional values are: host, pc. default value is: pc. lengthIncluded:whether to include the length of prefix when calculating the length of binary message. Optional values are: yes, no Default value is: no. |
<fString dataName="name" encoding="cp937"/> <selfLength/> For example, if you format a String “George. Wilhelm. T”, you will get the binary message: 12C785969987854B40E68993888593944B40E3 (hex value). |