net.named_data.jndn.encoding.tlv
public class TlvDecoder extends Object
Constructor and Description |
---|
TlvDecoder(ByteBuffer input)
Create a new TlvDecoder to decode the input.
|
Modifier and Type | Method and Description |
---|---|
void |
finishNestedTlvs(int endOffset)
Call this after reading all nested TLVs to skip any remaining unrecognized
TLVs and to check if the input buffer position after the final nested TLV
matches the endOffset returned by readNestedTlvsStart.
|
int |
getOffset()
Get the input buffer position (offset), used for the next read.
|
ByteBuffer |
getSlice(int beginOffset,
int endOffset)
Return a ByteBuffer slice of the input for the given offset range.
|
boolean |
peekType(int expectedType,
int endOffset)
Decode the type from the input starting at the input buffer position, and
if it is the expectedType, then return true, else false.
|
ByteBuffer |
readBlobTlv(int expectedType)
Decode the type and length from the input starting at the input buffer
position, expecting the type to be expectedType.
|
boolean |
readBooleanTlv(int expectedType,
int endOffset)
Peek at the next TLV, and if it has the expectedType then read a type and
value, ignoring the value, and return true.
|
int |
readExtendedVarNumber(int firstOctet)
Do the work of readVarNumber, given the firstOctet which is greater than
or equal to 253.
|
int |
readNestedTlvsStart(int expectedType)
Decode the type and length from the input starting at the input buffer
position, expecting the type to be expectedType.
|
long |
readNonNegativeInteger(int length)
Decode a non-negative integer in NDN-TLV and return it.
|
long |
readNonNegativeIntegerTlv(int expectedType)
Decode the type and length from the input starting at the input buffer
position, expecting the type to be expectedType.
|
ByteBuffer |
readOptionalBlobTlv(int expectedType,
int endOffset)
Peek at the next TLV, and if it has the expectedType then call readBlobTlv
and return the value.
|
long |
readOptionalNonNegativeIntegerTlv(int expectedType,
int endOffset)
Peek at the next TLV, and if it has the expectedType then call
readNonNegativeIntegerTlv and return the integer.
|
int |
readTypeAndLength(int expectedType)
Decode the type and length from this's input starting at the input buffer
position, expecting the type to be expectedType and return the length.
|
int |
readVarNumber()
Decode a VAR-NUMBER in NDN-TLV and return it.
|
void |
seek(int offset)
Set the offset into the input, used for the next read.
|
public TlvDecoder(ByteBuffer input)
input
- The input ByteBuffer whose position and limit are set to the
desired bytes to decode. This calls input.duplicate(), but does not copy
the underlying buffer whose contents must remain valid during the life of
this object.public final int readVarNumber() throws EncodingException
EncodingException
- if the VAR-NUMBER is 64-bit or read past the end
of the input.public final int readExtendedVarNumber(int firstOctet) throws EncodingException
firstOctet
- The first octet which is greater than or equal to 253,
used to decode the remaining bytes.EncodingException
- if the VAR-NUMBER is 64-bit or read past the end
of the input.public final int readTypeAndLength(int expectedType) throws EncodingException
expectedType
- The expected type as a 32-bit Java int.EncodingException
- if did not get the expected TLV type, or the TLV
length exceeds the buffer length, or the type is encoded as a 64-bit value,
or the length is encoded as a 64-bit value.public final int readNestedTlvsStart(int expectedType) throws EncodingException
expectedType
- The expected type as a 32-bit Java int.EncodingException
- if did not get the expected TLV type, or the TLV
length exceeds the buffer length, or the type is encoded as a 64-bit value,
or the length is encoded as a 64-bit value.public final void finishNestedTlvs(int endOffset) throws EncodingException
endOffset
- The offset of the end of the parent TLV, returned
by readNestedTlvsStart.EncodingException
- if the TLV length does not equal the total length
of the nested TLVs.public final boolean peekType(int expectedType, int endOffset) throws EncodingException
expectedType
- The expected type as a 32-bit Java int.endOffset
- The offset of the end of the parent TLV, returned
by readNestedTlvsStart.EncodingException
public final long readNonNegativeInteger(int length) throws EncodingException
length
- The number of bytes in the encoded integer.EncodingException
- if length is an invalid length for a TLV
non-negative integer or read past the end of the input.public final long readNonNegativeIntegerTlv(int expectedType) throws EncodingException
expectedType
- The expected type as a 32-bit Java int.EncodingException
- if did not get the expected TLV type or can't
decode the value.public final long readOptionalNonNegativeIntegerTlv(int expectedType, int endOffset) throws EncodingException
expectedType
- The expected type as a 32-bit Java int.endOffset
- The offset of the end of the parent TLV, returned
by readNestedTlvsStart.EncodingException
public final ByteBuffer readBlobTlv(int expectedType) throws EncodingException
expectedType
- The expected type as a 32-bit Java int.EncodingException
- if did not get the expected TLV type.public final ByteBuffer readOptionalBlobTlv(int expectedType, int endOffset) throws EncodingException
expectedType
- The expected type as a 32-bit Java int.endOffset
- The offset of the end of the parent TLV, returned
by readNestedTlvsStart.EncodingException
public final boolean readBooleanTlv(int expectedType, int endOffset) throws EncodingException
expectedType
- The expected type as a 32-bit Java int.endOffset
- The offset of the end of the parent TLV, returned
by readNestedTlvsStart.EncodingException
public final int getOffset()
public final void seek(int offset)
offset
- The new offset.public final ByteBuffer getSlice(int beginOffset, int endOffset)
beginOffset
- The offset in the input of the beginning of the slice.endOffset
- The offset in the input of the end of the slice.Copyright © 2016. All rights reserved.