new ProtobufTlv()
ProtobufTlv has static methods to encode and decode an Protobuf Message o
bject as NDN-TLV. The Protobuf tag value is used as the TLV type code. A
Protobuf message is encoded/decoded as a nested TLV encoding. Protobuf types
uint32, uint64 and enum are encoded/decoded as TLV nonNegativeInteger. (It is
an error if an enum value is negative.) Protobuf types bytes and string are
encoded/decoded as TLV bytes. The Protobuf type bool is encoded/decoded as a
TLV boolean (a zero length value for True, omitted for False). Other Protobuf
types are an error.
Protobuf has no "outer" message type, so you need to put your TLV message
inside an outer "typeless" message.
- Source:
Methods
(static) _decodeFieldValue()
This is a helper for _decodeMessageValue. Decode a single field and return
the value. Assume the field.type.name is not "message".
- Source:
(static) decode(message, descriptor, input)
Decode the input as NDN-TLV and update the fields of the Protobuf message
object.
Parameters:
Name | Type | Description |
---|---|---|
message |
ProtoBuf.Builder.Message | The Protobuf message object. This does not first clear the object. |
descriptor |
ProtoBuf.Reflect.T | The reflection descriptor for the message. For example, if the message is of type "MyNamespace.MyMessage" then the descriptor is builder.lookup("MyNamespace.MyMessage"). |
input |
Blob | Buffer | The buffer with the bytes to decode. |
- Source:
(static) encode(message, descriptor) → {Blob}
Encode the Protobuf message object as NDN-TLV. This calls
message.encodeAB() to ensure that all required fields are present and
raises an exception if not. (This does not use the result of toArrayBuffer().)
Parameters:
Name | Type | Description |
---|---|---|
message |
ProtoBuf.Builder.Message | The Protobuf message object. |
descriptor |
ProtoBuf.Reflect.T | The reflection descriptor for the message. For example, if the message is of type "MyNamespace.MyMessage" then the descriptor is builder.lookup("MyNamespace.MyMessage"). |
- Source:
Returns:
The encoded buffer in a Blob object.
- Type
- Blob