Class
Tree
          
SUMMARY: INNER | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD
 

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

public class UnsignedByteCodec      
Encodes and decodes SLIP message headers containing the payload length. On
encoding the codec converts the signed integer value into an unsigned byte
first ensuring that the length value will fit in an unsigned byte.
(ie. 0--> 2^8 - 1).


In order to decode SLIP messages, the codec reads the value from the buffer
into an integer and flips the high order bits to yeild the original unsigned
byte 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 byte
first ensuring that the length value will fit in an unsigned byte.
(ie. 0--> 2^8 - 1).


In order to decode SLIP messages, the codec reads the value from the buffer
into an integer and flips the high order bits to yeild the original unsigned
byte 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_BYTE
private final static int MAX_UNSIGNED_BYTE
the largest positive value that can be stored in an unsigned byte
Final.
Multiplicity:
1
Static.
 

UNSIGNED_BYTE_MASK
private final static int UNSIGNED_BYTE_MASK
Bit mask used to zero the high order bits of the integer read from
the buffer. The bit mask is used to convert the integer to the original
unsigned byte value on decoding
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 byte and then converted to
its original unsigned byte value by masking off its 24 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 byte. This function first ensures the
integer value will fit in an unsigned byte (0--> 2^8-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 byte
(0 --> 2^8-1)
 

Class
Tree
          
SUMMARY: INNER | FIELD | CONSTR | METHODDETAIL: FIELD | CONSTR | METHOD