pyndn.encoding package

Submodules

pyndn.encoding.element_reader module

This module defines the ElementReader class which lets you call onReceivedData multiple times which uses a TlvStructureDecoder to detect the end of a TLV element, and calls elementListener.onReceivedElement(element) with the element. This handles the case where a single call to onReceivedData may contain multiple elements.

class pyndn.encoding.element_reader.ElementReader(elementListener)[source]

Bases: object

Create an ElementReader with the elementListener and an initial buffer for saving partial data.

onReceivedData(data)[source]

Continue to read data until the end of an element, then call elementListener.onReceivedElement(element). The buffer passed to onReceivedElement is only valid during this call. If you need the data later, you must copy.

Parameters:data (An array type with int elements) – The buffer with the incoming element’s bytes.

pyndn.encoding.oid module

class pyndn.encoding.oid.OID(oid=None)[source]

Bases: object

getIntegerList()[source]
setIntegerList(oid)[source]

pyndn.encoding.protobuf_tlv module

This module defines the ProtobufTlv class which has static methods to encode and decode an Protobuf Message object 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.

class pyndn.encoding.protobuf_tlv.ProtobufTlv[source]

Bases: object

static decode(message, input)[source]

Decode the input as NDN-TLV and update the fields of the Protobuf message object.

Parameters:
  • message (google.protobuf.message) – The Protobuf message object. This does not first clear the object.
  • input (An array type with int elements) – The array with the bytes to decode.
static encode(message)[source]

Encode the Protobuf message object as NDN-TLV.

Parameters:message (google.protobuf.message) – The Protobuf message object. This calls message.IsInitialized() to ensure that all required fields are present and raises an exception if not.
Returns:The encoded buffer in a Blob object.
Return type:Blob

pyndn.encoding.tlv_0_1_1_wire_format module

class pyndn.encoding.tlv_0_1_1_wire_format.Tlv0_1_1WireFormat[source]

Bases: pyndn.encoding.wire_format.WireFormat

class SignatureHolder[source]

Bases: object

getSignature()[source]
setSignature(signature)[source]
Tlv0_1_1WireFormat.decodeControlParameters(controlParameters, input)[source]

Decode input as an NDN-TLV ControlParameters and set the fields of the controlParameters object.

Parameters:
  • controlParameters (ControlParameters) – The ControlParameters object whose fields are updated.
  • input (An array type with int elements) – The array with the bytes to decode.
Tlv0_1_1WireFormat.decodeData(data, input)[source]

Decode input as an NDN-TLV data packet, set the fields in the data object, and return the signed offsets.

Parameters:
  • data (Data) – The Data object whose fields are updated.
  • input (An array type with int elements) – The array with the bytes to decode.
Returns:

A Tuple of (signedPortionBeginOffset, signedPortionEndOffset) where signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion.

Return type:

(int, int)

Tlv0_1_1WireFormat.decodeEncryptedContent(encryptedContent, input)[source]

Decode input as an EncryptedContent in NDN-TLV and set the fields of the encryptedContent object.

Parameters:
  • encryptedContent (EncryptedContent) – The EncryptedContent object whose fields are updated.
  • input (An array type with int elements) – The array with the bytes to decode.
Tlv0_1_1WireFormat.decodeInterest(interest, input)[source]

Decode input as an NDN-TLV interest and set the fields of the interest object.

Parameters:
  • interest (Interest) – The Interest object whose fields are updated.
  • input (An array type with int elements) – The array with the bytes to decode.
Returns:

A Tuple of (signedPortionBeginOffset, signedPortionEndOffset) where signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion. The signed portion starts from the first name component and ends just before the final name component (which is assumed to be a signature for a signed interest).

Return type:

(int, int)

Tlv0_1_1WireFormat.decodeName(name, input)[source]

Decode input as an NDN-TLV name and set the fields of the Name object.

Parameters:
  • name (Name) – The Name object whose fields are updated.
  • input (An array type with int elements) – The array with the bytes to decode.
Tlv0_1_1WireFormat.decodeSignatureInfoAndValue(signatureInfo, signatureValue)[source]

Decode signatureInfo as a signature info and signatureValue as the related SignatureValue, and return a new object which is a subclass of Signature.

Parameters:
  • signatureInfo (An array type with int elements) – The array with the signature info input buffer to decode.
  • signatureValue (An array type with int elements) – The array with the signature value input buffer to decode.
Returns:

A new object which is a subclass of Signature.

Return type:

a subclass of Signature

Tlv0_1_1WireFormat.encodeControlParameters(controlParameters)[source]

Encode controlParameters and return the encoding.

Parameters:controlParameters (ControlParameters) – The ControlParameters object to encode.
Returns:A Blob containing the encoding.
Return type:Blob
Tlv0_1_1WireFormat.encodeData(data)[source]

Encode data in NDN-TLV and return the encoding and signed offsets.

Parameters:data (Data) – The Data object to encode.
Returns:A Tuple of (encoding, signedPortionBeginOffset, signedPortionEndOffset) where encoding is a Blob containing the encoding, signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion.
Return type:(Blob, int, int)
Tlv0_1_1WireFormat.encodeEncryptedContent(encryptedContent)[source]

Encode the EncryptedContent in NDN-TLV and return the encoding.

Parameters:encryptedContent (EncryptedContent) – The EncryptedContent object to encode.
Returns:A Blob containing the encoding.
Return type:Blob
Tlv0_1_1WireFormat.encodeInterest(interest)[source]

Encode interest in NDN-TLV and return the encoding.

Parameters:interest (Interest) – The Interest object to encode.
Returns:A Tuple of (encoding, signedPortionBeginOffset, signedPortionEndOffset) where encoding is a Blob containing the encoding, signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion. The signed portion starts from the first name component and ends just before the final name component (which is assumed to be a signature for a signed interest).
Return type:(Blob, int, int)
Tlv0_1_1WireFormat.encodeName(name)[source]

Encode name in NDN-TLV and return the encoding.

Parameters:name (Name) – The Name object to encode.
Returns:A Blob containing the encoding.
Return type:Blob
Tlv0_1_1WireFormat.encodeSignatureInfo(signature)[source]

Encode signature as an NDN-TLV SignatureInfo and return the encoding.

Parameters:signature (An object of a subclass of Signature) – An object of a subclass of Signature to encode.
Returns:A Blob containing the encoding.
Return type:Blob
Tlv0_1_1WireFormat.encodeSignatureValue(signature)[source]

Encode the signatureValue in the Signature object as an NDN-TLV SignatureValue (the signature bits) and return the encoding.

Parameters:signature (An object of a subclass of Signature) – An object of a subclass of Signature with the signature value to encode.
Returns:A Blob containing the encoding.
Return type:Blob
classmethod Tlv0_1_1WireFormat.get()[source]

Get a singleton instance of a Tlv0_1_1WireFormat. To always use the preferred version NDN-TLV, you should use TlvWireFormat.get().

Returns:The singleton instance.
Return type:Tlv0_1_1WireFormat

pyndn.encoding.tlv_0_1_wire_format module

This module defines the Tlv0_1WireFormat class which extends Tlv0_1_1WireFormat so that it is an alias in case any applications use Tlv0_1WireFormat directly. These two wire formats are the same except that Tlv0_1_1WireFormat adds support for Sha256WithEcdsaSignature.

class pyndn.encoding.tlv_0_1_wire_format.Tlv0_1WireFormat[source]

Bases: pyndn.encoding.tlv_0_1_1_wire_format.Tlv0_1_1WireFormat

classmethod get()[source]

Get a singleton instance of a Tlv0_1WireFormat.

Returns:The singleton instance.
Return type:Tlv0_1WireFormat

pyndn.encoding.tlv_wire_format module

class pyndn.encoding.tlv_wire_format.TlvWireFormat[source]

Bases: pyndn.encoding.tlv_0_1_1_wire_format.Tlv0_1_1WireFormat

classmethod get()[source]

Get a singleton instance of a TlvWireFormat. Assuming that the default wire format was set with WireFormat.setDefaultWireFormat(TlvWireFormat.get()), you can check if this is the default wire encoding with if WireFormat.getDefaultWireFormat() == TlvWireFormat.get().

Returns:The singleton instance.
Return type:TlvWireFormat

pyndn.encoding.wire_format module

This module defines the WireFormat class which is an abstract base class for encoding and decoding Interest, Data, etc. with a specific wire format. You should use a derived class such as TlvWireFormat.

class pyndn.encoding.wire_format.WireFormat[source]

Bases: object

decodeControlParameters(controlParameters, input)[source]

Decode input as a controlParameters and set the fields of the controlParameters object. Your derived class should override.

Parameters:
  • controlParameters (ControlParameters) – The ControlParameters object whose fields are updated.
  • input (An array type with int elements) – The array with the bytes to decode.
Raises RuntimeError:
 

for unimplemented if the derived class does not override.

decodeData(data, input)[source]

Decode input as a data packet, set the fields in the data object, and return the signed offsets. Your derived class should override.

Parameters:
  • data (Data) – The Data object whose fields are updated.
  • input (An array type with int elements) – The array with the bytes to decode.
Returns:

A Tuple of (signedPortionBeginOffset, signedPortionEndOffset) where signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion.

Return type:

(int, int)

Raises RuntimeError:
 

for unimplemented if the derived class does not override.

decodeEncryptedContent(encryptedContent, input)[source]

Decode input as an EncryptedContent and set the fields of the encryptedContent object. Your derived class should override.

Parameters:
  • encryptedContent (EncryptedContent) – The EncryptedContent object whose fields are updated.
  • input (An array type with int elements) – The array with the bytes to decode.
Raises RuntimeError:
 

for unimplemented if the derived class does not override.

decodeInterest(interest, input)[source]

Decode input as an interest and set the fields of the interest object. Your derived class should override.

Parameters:
  • interest (Interest) – The Interest object whose fields are updated.
  • input (An array type with int elements) – The array with the bytes to decode.
Returns:

A Tuple of (signedPortionBeginOffset, signedPortionEndOffset) where signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion. The signed portion starts from the first name component and ends just before the final name component (which is assumed to be a signature for a signed interest).

Return type:

(int, int)

Raises RuntimeError:
 

for unimplemented if the derived class does not override.

decodeName(name, input)[source]

Decode input as a name and set the fields of the Name object. Your derived class should override.

Parameters:
  • name (Name) – The Name object whose fields are updated.
  • input (An array type with int elements) – The array with the bytes to decode.
Raises RuntimeError:
 

for unimplemented if the derived class does not override.

decodeSignatureInfoAndValue(signatureInfo, signatureValue)[source]

Decode signatureInfo as a signature info and signatureValue as the related SignatureValue, and return a new object which is a subclass of Signature. Your derived class should override.

Parameters:
  • signatureInfo (An array type with int elements) – The array with the signature info input buffer to decode.
  • signatureValue (An array type with int elements) – The array with the signature value input buffer to decode.
Returns:

A new object which is a subclass of Signature.

Return type:

a subclass of Signature

Raises RuntimeError:
 

for unimplemented if the derived class does not override.

encodeControlParameters(controlParameters)[source]

Encode controlParameters and return the encoding. Your derived class should override.

Parameters:controlParameters (ControlParameters) – The ControlParameters object to encode.
Returns:A Blob containing the encoding.
Return type:Blob
Raises RuntimeError:
 for unimplemented if the derived class does not override.
encodeData(data)[source]

Encode data and return the encoding and signed offsets. Your derived class should override.

Parameters:data (Data) – The Data object to encode.
Returns:A Tuple of (encoding, signedPortionBeginOffset, signedPortionEndOffset) where encoding is a Blob containing the encoding, signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion.
Return type:(Blob, int, int)
Raises RuntimeError:
 for unimplemented if the derived class does not override.
encodeEncryptedContent(encryptedContent)[source]

Encode the EncryptedContent and return the encoding. Your derived class should override.

Parameters:encryptedContent (EncryptedContent) – The EncryptedContent object to encode.
Returns:A Blob containing the encoding.
Return type:Blob
Raises RuntimeError:
 for unimplemented if the derived class does not override.
encodeInterest(interest)[source]

Encode interest and return the encoding. Your derived class should override.

Parameters:interest (Interest) – The Interest object to encode.
Returns:A Tuple of (encoding, signedPortionBeginOffset, signedPortionEndOffset) where encoding is a Blob containing the encoding, signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion. The signed portion starts from the first name component and ends just before the final name component (which is assumed to be a signature for a signed interest).
Return type:(Blob, int, int)
Raises RuntimeError:
 for unimplemented if the derived class does not override.
encodeName(name)[source]

Encode name and return the encoding. Your derived class should override.

Parameters:name (Name) – The Name object to encode.
Returns:A Blob containing the encoding.
Return type:Blob
Raises RuntimeError:
 for unimplemented if the derived class does not override.
encodeSignatureInfo(signature)[source]

Encode signature as a SignatureInfo and return the encoding. Your derived class should override.

Parameters:signature (An object of a subclass of Signature) – An object of a subclass of Signature to encode.
Returns:A Blob containing the encoding.
Return type:Blob
Raises RuntimeError:
 for unimplemented if the derived class does not override.
encodeSignatureValue(signature)[source]

Encode the signatureValue in the Signature object as a SignatureValue (the signature bits) and return the encoding. Your derived class should override.

Parameters:signature (An object of a subclass of Signature) – An object of a subclass of Signature with the signature value to encode.
Returns:A Blob containing the encoding.
Return type:Blob
Raises RuntimeError:
 for unimplemented if the derived class does not override.
classmethod getDefaultWireFormat()[source]

Return the default WireFormat used by default encoding and decoding methods which was set with setDefaultWireFormat.

Returns:The WireFormat object.
Return type:A subclass of WireFormat.
classmethod setDefaultWireFormat(wireFormat)[source]

Set the static default WireFormat used by default encoding and decoding methods.

Parameters:wireFormat (A subclass of WireFormat) – An object of a subclass of WireFormat.

Module contents