net.named_data.jndn.encoding.tlv
public class TlvEncoder extends Object
Constructor and Description |
---|
TlvEncoder()
Create a new TlvEncoder with a default DynamicByteBuffer.
|
TlvEncoder(int initialCapacity)
Create a new TlvEncoder to use a DynamicByteBuffer with the initialCapacity.
|
Modifier and Type | Method and Description |
---|---|
int |
getLength()
Get the number of bytes that have been written to the output.
|
ByteBuffer |
getOutput()
Return a slice of the output buffer up to the current length of the output
encoding.
|
void |
writeBlobTlv(int type,
ByteBuffer value)
Write the type, then the length of the buffer then the buffer value from
its position() to limit() to the output just before getLength() from the
back.
|
void |
writeBuffer(ByteBuffer buffer)
Write the buffer from its position() to limit() to the output just
before getLength() from the back.
|
void |
writeNonNegativeInteger(long value)
Encode value as a non-negative integer and write it to the output just
before getLength() from the back.
|
void |
writeNonNegativeIntegerTlv(int type,
long value)
Write the type, then the length of the encoded value then encode value as a
non-negative integer and write it to the output just before getLength()
from the back.
|
void |
writeOptionalBlobTlv(int type,
ByteBuffer value)
If the byte buffer value is null or value.remaining() is zero then do
nothing, otherwise call writeBlobTlv.
|
void |
writeOptionalNonNegativeIntegerTlv(int type,
long value)
If value is negative or null then do nothing, otherwise call
writeNonNegativeIntegerTlv.
|
void |
writeOptionalNonNegativeIntegerTlvFromDouble(int type,
double value)
If value is negative or null then do nothing, otherwise call
writeNonNegativeIntegerTlv.
|
void |
writeTypeAndLength(int type,
int length)
Encode the type and length as VAR-NUMBER and write to the output just
before getLength() from the back.
|
void |
writeVarNumber(int varNumber)
Encode varNumber as a VAR-NUMBER in NDN-TLV and write it to the output just
before getLength() from the back.
|
public TlvEncoder(int initialCapacity)
initialCapacity
- The initial capacity of buffer().public TlvEncoder()
public final int getLength()
public final void writeVarNumber(int varNumber)
varNumber
- The non-negative number to encode. This is a Java 32-bit
int, so this does not support encoding a 64-bit VAR-NUMBER.public final void writeTypeAndLength(int type, int length)
type
- The type of the TLV. This is a Java 32-bit int, so this does
not support encoding a 64-bit type code.length
- The non-negative length of the TLV. This is a Java 32-bit
int, so this does not support encoding a 64-bit length.public final void writeNonNegativeInteger(long value)
value
- The non-negative integer to encode. This is a Java 64-bit
long, so encoding of 64-bit values is supported (actually 63-bit because
a Java long is signed).Error
- if the value is negative.public final void writeNonNegativeIntegerTlv(int type, long value)
type
- The type of the TLV. This is a Java 32-bit int, so this does
not support encoding a 64-bit type code.value
- The non-negative integer to encode. This is a Java 64-bit
long, so encoding of 64-bit values is supported (actually 63-bit because
a Java long is signed).Error
- if the value is negative.public final void writeOptionalNonNegativeIntegerTlv(int type, long value)
type
- The type of the TLV. This is a Java 32-bit int, so this does
not support encoding a 64-bit type code.value
- If negative do nothing, otherwise the integer to encode. This
is a Java 64-bit long, so encoding of 64-bit values is supported (actually
63-bit because a Java long is signed).public final void writeOptionalNonNegativeIntegerTlvFromDouble(int type, double value)
type
- The type of the TLV. This is a Java 32-bit int, so this does
not support encoding a 64-bit type code.value
- If negative do nothing, otherwise use (long)Math.round(value).public final void writeBuffer(ByteBuffer buffer)
buffer
- The byte buffer with the bytes to write. If buffer is null,
then do nothing.public final void writeBlobTlv(int type, ByteBuffer value)
type
- The type of the TLV. This is a Java 32-bit int, so this does
not support encoding a 64-bit type code.value
- The byte buffer with the bytes of the blob. If value is null,
then just write the type and length 0.public final void writeOptionalBlobTlv(int type, ByteBuffer value)
type
- The type of the TLV. This is a Java 32-bit int, so this does
not support encoding a 64-bit type code.value
- If null or value.remaining() is zero do nothing, otherwise
the buffer with the bytes of the blob.public final ByteBuffer getOutput()
Copyright © 2016. All rights reserved.