Class
Tree
          
PREV CLASS NEXT CLASS
SUMMARY: INNER | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD
 

com.newstep.solid.netio.slip.codec
Class UnsignedShortCodec
All Implemented Interfaces:
       SlipMessageHeaderCodec

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
to Interface SlipMessageHeaderCodec
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
decode(ByteBuffer buffer)
public void
encode(ByteBuffer buffer, Integer length)
Field Detail
MAX_UNSIGNED_SHORT
private final static int MAX_UNSIGNED_SHORT
The maximum positive value that can be stored in an unsigned short
Final.
Multiplicity:
1
Static.
 

UNSIGNED_SHORT_MASK
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.
 
Method Detail
decode
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
 

encode
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)
 

Class
Tree
          
PREV CLASS NEXT CLASS
SUMMARY: INNER | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD