Class: TlvEncoder

TlvEncoder

new TlvEncoder(initialCapacity)

Create a new TlvEncoder with an initialCapacity for the encoding buffer.
Parameters:
Name Type Description
initialCapacity number (optional) The initial capacity of the encoding buffer. If omitted, use a default value.
Source:

Methods

getLength() → {number}

Get the number of bytes that have been written to the output. You can save this number, write sub TLVs, then subtract the new length from this to get the total length of the sub TLVs.
Source:
Returns:
The number of bytes that have been written to the output.
Type
number

getOutput() → {Buffer}

Get a slice of the encoded bytes.
Source:
Returns:
A slice backed by the encoding Buffer.
Type
Buffer

writeBlobTlv(type, value)

Write the type, then the length of the buffer then the buffer value to this.output just before this.length from the back. Advance this.length.
Parameters:
Name Type Description
type number The type of the TLV.
value Buffer The byte array with the bytes of the blob. If value is null, then just write the type and length 0.
Source:

writeBuffer(buffer)

Write the buffer value to this.output just before this.length from the back. Advance this.length.
Parameters:
Name Type Description
buffer Buffer The byte array with the bytes to write. If value is null, then do nothing.
Source:

writeNonNegativeInteger(value)

Write value as a non-negative integer and write it to this.output just before this.length from the back. Advance this.length.
Parameters:
Name Type Description
value number The non-negative integer to encode.
Source:

writeNonNegativeIntegerTlv(type, value)

Write the type, then the length of the encoded value then encode value as a non-negative integer and write it to this.output just before this.length from the back. Advance this.length.
Parameters:
Name Type Description
type number The type of the TLV.
value number The non-negative integer to encode.
Source:

writeOptionalBlobTlv(type, value)

If the byte array is null or zero length then do nothing, otherwise call writeBlobTlv.
Parameters:
Name Type Description
type number The type of the TLV.
value Buffer If null or zero length do nothing, otherwise the byte array with the bytes of the blob.
Source:

writeOptionalNonNegativeIntegerTlv(type, value)

If value is negative or null then do nothing, otherwise call writeNonNegativeIntegerTlv.
Parameters:
Name Type Description
type number The type of the TLV.
value number If negative or None do nothing, otherwise the integer to encode.
Source:

writeTypeAndLength(type, length)

Encode the type and length as VAR-NUMBER and write to this.output just before this.length from the back. Advance this.length.
Parameters:
Name Type Description
type number The type of the TLV.
length number The non-negative length of the TLV.
Source:

writeVarNumber(varNumber)

Encode varNumber as a VAR-NUMBER in NDN-TLV and write it to this.output just before this.length from the back. Advance this.length.
Parameters:
Name Type Description
varNumber number The non-negative number to encode.
Source: