| | | | SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
|
|
com.newstep.solid.netio.slip.codec
public class UnsignedShortCodec
Encodes and decodes SLIP message headers containing the payload length. On
encoding the codec converts the signed integer value into an unsigned short
first ensuring that the length value will fit in an unsigned short.
(ie. 0--> 2^16 - 1).
In order to decode SLIP message headers, the codec reads the value from the
buffer into an integer and flips the high order bits to yield the original
unsigned short value as a signed integer
Implements:
SlipMessageHeaderCodec
Links:
Implementation Implementation Link
Encodes and decodes SLIP message headers containing the payload length. On
encoding the codec converts the signed integer value into an unsigned short
first ensuring that the length value will fit in an unsigned short.
(ie. 0--> 2^16 - 1).
In order to decode SLIP message headers, the codec reads the value from the
buffer into an integer and flips the high order bits to yield the original
unsigned short value as a signed integer
| Field Summary |
private final static int |
|
private final static int |
|
| Method Summary |
public int |
|
public void |
encode(ByteBuffer buffer, Integer length) |
private final static int MAX_UNSIGNED_SHORT
The maximum positive value that can be stored in an unsigned short
Final.
Multiplicity:
1
Static.
private final static int UNSIGNED_SHORT_MASK
Bitmask used to convert from signed integer to unsigned short value by
masking off the 16 high order bits.
Final.
Multiplicity:
1
Static.
public int decode (ByteBuffer buffer)
Decodes the length value from the specified buffer. The value is read
into a signed integer from the ByteBuffer as a short and then converted to
its original unsigned short value by masking off its 16 high order bits.
Parameters:
buffer The ByteBuffer from which to decode the payload length
value
public void encode (ByteBuffer buffer, Integer length)
Encodes the payload length into the specified buffer by converting the
signed integer value into an unsigned short. This function first ensures the
integer value will fit in an unsigned short (0--> 2^16-1)
Parameters:
buffer The ByteBuffer into which the length header should be
encoded
length The signed integer value representing the size of the SLIP
message's associated payload (in bytes). Must fit into a unsigned short
(0 --> 2^15-1)
| | | | SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
|
|