Java Reference
In-Depth Information
Call the nextToken() method for each field: lines 19-23
For each field, we call Framer.nextToken() with the appropriate delimiter and convert
the result according to the specified encoding.
Construct ItemQuote : lines 24-28
Convert to native types using the wrapper conversion methods and test for the
presence of the flag characters in the last field.
3. Packet decode() : lines 31-35
Extract the data, convert to a stream, and call the stream decode() method.
3.4.2 Combined Data Representation
Our next encoding represents the integers of the ItemQuote as fixed-size, binary numbers:
itemNumber as 64 bits, and quantity and unitPrice as 32 bits. It encodes the boolean values as
flag bits, which occupy the smallest possible space in an encoded message. Also, the variable-
length string itemDescription is encoded in a field with an explicit length indication. The binary
encoding and decoding share coding constants in the ItemQuoteBinConst interface.
ItemQuoteBinConst.java
0 public interface ItemQuoteBinConst {
1
public static final String DEFAULT_ENCODING = "ISO_8859_1";
2
public static final int DISCOUNT_FLAG=1<<7;
3
public static final int IN_STOCK_FLAG = 1 << 0;
4
public static final int MAX_DESC_LEN = 255;
5
public static final int MAX_WIRE_LENGTH = 1024;
6 }
ItemQuoteBinConst.java
ItemQuoteEncoderBin implements the binary encoding.
ItemQuoteEncoderBin.java
0 import java.io.*; // for ByteArrayOutputStream and DataOutputStream
1
2 public class ItemQuoteEncoderBin implements ItemQuoteEncoder, ItemQuoteBinConst {
3
4
private String encoding; // Character encoding
5
6
public ItemQuoteEncoderBin() {
7
encoding = DEFAULT_ENCODING;
8
}
9
 
Search WWH ::




Custom Search