jQuery in Action, 3rd edition
The moose likes I/O and Streams and the fly likes How to Pack/Unpack message? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to Pack/Unpack message?" Watch "How to Pack/Unpack message?" New topic

How to Pack/Unpack message?

Vijay Bhuruk
Ranch Hand

Joined: Feb 28, 2008
Posts: 31

Hi friends,

Can you please confirm that possible to code below steps in java?I am new to these stuff such as network-byte order.
Please can you suggest me tutorials on the same?
Thanks in advance.

To pack a CTI message:

Step 1 Allocate a continuous block of memory.
Step 2 Add the message header to the beginning of the memory block.
Reserve a 4-byte place for the BodyLength field to fill in later when you accurately know the message
body length (when you have added all the Body fields). Convert the 4-byte MessageTypeID to
network-byte order and add it to the memory block after the reserved BodyLength field.
Step 3 Convert each of the fixed message fields, one by one, to network-byte order, if needed, and add them to
the memory block in the appropriate order according to the MessageTypeID.
Step 4 Convert the floating data fields, one by one, if needed, to the network-byte order. Add the fields in the
floating part of the message into the memory block without any gap between the fields.
Step 5 Repeat this process to pack the rest of the floating fields until the end of the message.
Step 6 Remember to convert the BodyLength bytes from host-byte order to network-byte order. Then update
the BodyLength field in the message header part of the memory block after all the floating fields are
added to accurately reflect the message body length.
To unpack a CTI message:

Step 1 Read the first 4 bytes as an unsigned integer. This value is the message BodyLength. Remember to
convert the BodyLength bytes from network-byte order to host-byte order.
Step 2 Make sure all the BodyLength bytes are available from the network before further unpacking.
Step 3 Read the next 4 bytes and convert them to a host-byte-order unsigned integer. This value is the
Step 4 Based on the MessageTypeID, you can then use the message body definition to find out the fixed fields
and their appropriate order in the fixed part of the message.
Step 5 Read each field, one by one, and convert it to host data-byte order, if needed.
Step 6 Based on the FieldDataID value and its definition, convert the floating data fields to the host-byte order,
if necessary.
Step 7 Repeat this process to unpack the rest of floating fields until the end of the message. The end of the
message is determined by the Message BodyLength.
I agree. Here's the link: http://aspose.com/file-tools
subject: How to Pack/Unpack message?
It's not a secret anymore!