def decodeForwardingEntry(self, forwardingEntry, input): """ Decode input as an forwardingEntry and set the fields of the forwardingEntry object. :param forwardingEntry: The ForwardingEntry object whose fields are updated. :type forwardingEntry: ForwardingEntry :param input: The array with the bytes to decode. :type input: An array type with int elements """ decoder = TlvDecoder(input) endOffset = decoder.readNestedTlvsStart(Tlv.ForwardingEntry) actionBytes = decoder.readOptionalBlobTlv(Tlv.Action, endOffset) if actionBytes != None: # Convert bytes to a str. forwardingEntry.setAction("".join(map(chr, actionBytes))) else: forwardingEntry.setAction(None) if decoder.peekType(Tlv.Name, endOffset): self._decodeName(forwardingEntry.getPrefix(), decoder) else: forwardingEntry.getPrefix().clear() forwardingEntry.setFaceId( decoder.readOptionalNonNegativeIntegerTlv(Tlv.FaceID, endOffset)) forwardingEntryFlags = decoder.readOptionalNonNegativeIntegerTlv( Tlv.ForwardingFlags, endOffset) if forwardingEntryFlags != None: forwardingEntry.getForwardingFlags().setForwardingEntryFlags( forwardingEntryFlags) else: # This sets the default flags. forwardingEntry.setForwardingFlags(ForwardingFlags()) forwardingEntry.setFreshnessPeriod( decoder.readOptionalNonNegativeIntegerTlvAsFloat( Tlv.FreshnessPeriod, endOffset)) decoder.finishNestedTlvs(endOffset)
def decodeForwardingEntry(self, forwardingEntry, input): """ Decode input as an forwardingEntry and set the fields of the forwardingEntry object. :param forwardingEntry: The ForwardingEntry object whose fields are updated. :type forwardingEntry: ForwardingEntry :param input: The array with the bytes to decode. :type input: An array type with int elements """ decoder = TlvDecoder(input) endOffset = decoder.readNestedTlvsStart(Tlv.ForwardingEntry) actionBytes = decoder.readOptionalBlobTlv(Tlv.Action, endOffset) if actionBytes != None: # Convert bytes to a str. forwardingEntry.setAction("".join(map(chr, actionBytes))) else: forwardingEntry.setAction(None) if decoder.peekType(Tlv.Name, endOffset): self._decodeName(forwardingEntry.getPrefix(), decoder) else: forwardingEntry.getPrefix().clear() forwardingEntry.setFaceId( decoder.readOptionalNonNegativeIntegerTlv(Tlv.FaceID, endOffset)) forwardingEntryFlags = decoder.readOptionalNonNegativeIntegerTlv( Tlv.ForwardingFlags, endOffset) if forwardingEntryFlags != None: forwardingEntry.getForwardingFlags().setForwardingEntryFlags( forwardingEntryFlags) else: # This sets the default flags. forwardingEntry.setForwardingFlags(ForwardingFlags()) forwardingEntry.setFreshnessPeriod( decoder.readOptionalNonNegativeIntegerTlvAsFloat( Tlv.FreshnessPeriod, endOffset)) decoder.finishNestedTlvs(endOffset)
def decodeEncryptedContent(self, encryptedContent, input): """ Decode input as an EncryptedContent in NDN-TLV and set the fields of the encryptedContent object. :param EncryptedContent encryptedContent: The EncryptedContent object whose fields are updated. :param input: The array with the bytes to decode. :type input: An array type with int elements """ decoder = TlvDecoder(input) endOffset = decoder.readNestedTlvsStart(Tlv.Encrypt_EncryptedContent) Tlv0_1_1WireFormat._decodeKeyLocator( Tlv.KeyLocator, encryptedContent.getKeyLocator(), decoder) encryptedContent.setAlgorithmType( decoder.readNonNegativeIntegerTlv(Tlv.Encrypt_EncryptionAlgorithm)) encryptedContent.setInitialVector( Blob(decoder.readOptionalBlobTlv (Tlv.Encrypt_InitialVector, endOffset), True)) encryptedContent.setPayload( Blob(decoder.readBlobTlv(Tlv.Encrypt_EncryptedPayload), True)) decoder.finishNestedTlvs(endOffset)
def decodeControlParameters(self, controlParameters, input): """ Decode input as an NDN-TLV ControlParameters and set the fields of the controlParameters object. :param ControlParameters controlParameters: The ControlParameters object whose fields are updated. :param input: The array with the bytes to decode. :type input: An array type with int elements """ controlParameters.clear() decoder = TlvDecoder(input) endOffset = decoder.readNestedTlvsStart( Tlv.ControlParameters_ControlParameters) # decode name if decoder.peekType(Tlv.Name, endOffset): name = Name() self._decodeName(name, decoder) controlParameters.setName(name) # decode face ID controlParameters.setFaceId( decoder.readOptionalNonNegativeIntegerTlv( Tlv.ControlParameters_FaceId, endOffset)) # decode URI if decoder.peekType(Tlv.ControlParameters_Uri, endOffset): uri = Blob( decoder.readOptionalBlobTlv(Tlv.ControlParameters_Uri, endOffset), False) controlParameters.setUri(str(uri)) # decode integers controlParameters.setLocalControlFeature( decoder.readOptionalNonNegativeIntegerTlv( Tlv.ControlParameters_LocalControlFeature, endOffset)) controlParameters.setOrigin( decoder.readOptionalNonNegativeIntegerTlv( Tlv.ControlParameters_Origin, endOffset)) controlParameters.setCost( decoder.readOptionalNonNegativeIntegerTlv( Tlv.ControlParameters_Cost, endOffset)) # set forwarding flags if decoder.peekType(Tlv.ControlParameters_Flags, endOffset): flags = ForwardingFlags() flags.setNfdForwardingFlags( decoder.readNonNegativeIntegerTlv(Tlv.ControlParameters_Flags)) controlParameters.setForwardingFlags(flags) # decode strategy if decoder.peekType(Tlv.ControlParameters_Strategy, endOffset): strategyEndOffset = decoder.readNestedTlvsStart( Tlv.ControlParameters_Strategy) self._decodeName(controlParameters.getStrategy(), decoder) decoder.finishNestedTlvs(strategyEndOffset) # decode expiration period controlParameters.setExpirationPeriod( decoder.readOptionalNonNegativeIntegerTlv( Tlv.ControlParameters_ExpirationPeriod, endOffset)) decoder.finishNestedTlvs(endOffset)