public static class TlvBufferUtils.TlvConstructor extends Object
A constructor is created specifying the size of the Type (T) and Length (L) fields. A specification of zero size T field is allowed - resulting in LV type format.
The byte array is either provided (using
wrap(byte[])
) or allocated (using
allocate(int)
).
Values are added to the structure using the TlvConstructor.put*()
methods.
The final byte array is obtained using getArray()
and getActualLength()
methods.
Constructor and Description |
---|
TlvConstructor(int typeSize,
int lengthSize)
Define a TLV constructor with the specified size of the Type (T) and
Length (L) fields.
|
Modifier and Type | Method and Description |
---|---|
TlvBufferUtils.TlvConstructor |
allocate(int capacity)
Allocates a new byte array to be used ot construct a TLV.
|
int |
getActualLength()
Returns the size of the TLV formatted portion of the wrapped or
allocated byte array.
|
byte[] |
getArray()
Returns the constructed TLV formatted byte-array.
|
TlvBufferUtils.TlvConstructor |
putByte(int type,
byte b)
Copies a byte into the TLV with the indicated type.
|
TlvBufferUtils.TlvConstructor |
putByteArray(int type,
byte[] array)
Copies a byte array into the TLV with the indicated type.
|
TlvBufferUtils.TlvConstructor |
putByteArray(int type,
byte[] array,
int offset,
int length)
Copies a byte array into the TLV with the indicated type.
|
TlvBufferUtils.TlvConstructor |
putInt(int type,
int data)
Copies integer into the TLV with the indicated type.
|
TlvBufferUtils.TlvConstructor |
putShort(int type,
short data)
Copies short into the TLV with the indicated type.
|
TlvBufferUtils.TlvConstructor |
putString(int type,
String data)
Copies a String's byte representation into the TLV with the indicated
type.
|
TlvBufferUtils.TlvConstructor |
putZeroLengthElement(int type)
Places a zero length element (i.e.
|
TlvBufferUtils.TlvConstructor |
wrap(byte[] array)
Set the byte array to be used to construct the TLV.
|
public TlvConstructor(int typeSize, int lengthSize)
typeSize
- Number of bytes used for the Type (T) field. Values
of 0, 1, or 2 bytes are allowed. A specification of 0
bytes implies that the field being constructed has the LV
format rather than the TLV format.lengthSize
- Number of bytes used for the Length (L) field.
Values of 1 or 2 bytes are allowed.public TlvBufferUtils.TlvConstructor wrap(byte[] array)
array
- Byte array to be formatted.ctr.putXXX(..).putXXX(..)
.public TlvBufferUtils.TlvConstructor allocate(int capacity)
capacity
- The size of the byte array to be allocated.ctr.putXXX(..).putXXX(..)
.public TlvBufferUtils.TlvConstructor putByte(int type, byte b)
TlvConstructor(int, int)
) the type field is ignored.type
- The value to be placed into the Type field.b
- The byte to be inserted into the structure.ctr.putXXX(..).putXXX(..)
.public TlvBufferUtils.TlvConstructor putByteArray(int type, byte[] array, int offset, int length)
TlvConstructor(int, int)
) the type field is ignored.type
- The value to be placed into the Type field.array
- The array to be copied into the TLV structure.offset
- Start copying from the array at the specified offset.length
- Copy the specified number (length) of bytes from the
array.ctr.putXXX(..).putXXX(..)
.public TlvBufferUtils.TlvConstructor putByteArray(int type, byte[] array)
TlvConstructor(int, int)
) the type field is ignored.type
- The value to be placed into the Type field.array
- The array to be copied (in full) into the TLV structure.ctr.putXXX(..).putXXX(..)
.public TlvBufferUtils.TlvConstructor putZeroLengthElement(int type)
TlvConstructor(int, int)
) the type field is
ignored.type
- The value to be placed into the Type field.ctr.putXXX(..).putXXX(..)
.public TlvBufferUtils.TlvConstructor putShort(int type, short data)
TlvConstructor(int, int)
) the type field is ignored.type
- The value to be placed into the Type field.data
- The short to be inserted into the structure.ctr.putXXX(..).putXXX(..)
.public TlvBufferUtils.TlvConstructor putInt(int type, int data)
TlvConstructor(int, int)
) the type field is ignored.type
- The value to be placed into the Type field.data
- The integer to be inserted into the structure.ctr.putXXX(..).putXXX(..)
.public TlvBufferUtils.TlvConstructor putString(int type, String data)
TlvConstructor(int, int)
) the type field is
ignored.type
- The value to be placed into the Type field.data
- The string whose bytes are to be inserted into the
structure.ctr.putXXX(..).putXXX(..)
.public byte[] getArray()
wrap(byte[])
) or allocated (
allocate(int)
) array - which isn't necessarily
the actual size of the formatted data. Use
getActualLength()
to obtain the size of the
formatted data.public int getActualLength()
getArray()
.