本文整理汇总了Python中pyndn.encoding.tlv.tlv_encoder.TlvEncoder.getOutput方法的典型用法代码示例。如果您正苦于以下问题:Python TlvEncoder.getOutput方法的具体用法?Python TlvEncoder.getOutput怎么用?Python TlvEncoder.getOutput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.encoding.tlv.tlv_encoder.TlvEncoder
的用法示例。
在下文中一共展示了TlvEncoder.getOutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encodeForwardingEntry
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeForwardingEntry(self, forwardingEntry):
"""
Encode forwardingEntry and return the encoding.
:param forwardingEntry: The ForwardingEntry object to encode.
:type forwardingEntry: ForwardingEntry
:return: A Blob containing the encoding.
:rtype: Blob
"""
encoder = TlvEncoder(256)
saveLength = len(encoder)
# Encode backwards.
encoder.writeOptionalNonNegativeIntegerTlvFromFloat(
Tlv.FreshnessPeriod, forwardingEntry.getFreshnessPeriod())
encoder.writeNonNegativeIntegerTlv(
Tlv.ForwardingFlags,
forwardingEntry.getForwardingFlags().getForwardingEntryFlags())
encoder.writeOptionalNonNegativeIntegerTlv(
Tlv.FaceID, forwardingEntry.getFaceId())
self._encodeName(forwardingEntry.getPrefix(), encoder)
if (forwardingEntry.getAction() != None and
len(forwardingEntry.getAction()) > 0):
# Convert str to a bytearray.
encoder.writeBlobTlv(
Tlv.Action, bytearray(forwardingEntry.getAction(), 'ascii'))
encoder.writeTypeAndLength(Tlv.ForwardingEntry,
len(encoder) - saveLength)
return Blob(encoder.getOutput(), False)
示例2: encodeEncryptedContent
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeEncryptedContent(self, encryptedContent):
"""
Encode the EncryptedContent in NDN-TLV and return the encoding.
:param EncryptedContent encryptedContent: The EncryptedContent object to
encode.
:return: A Blob containing the encoding.
:rtype: Blob
"""
encoder = TlvEncoder(256)
saveLength = len(encoder)
# Encode backwards.
encoder.writeBlobTlv(
Tlv.Encrypt_EncryptedPayload, encryptedContent.getPayload().buf())
encoder.writeOptionalBlobTlv(
Tlv.Encrypt_InitialVector, encryptedContent.getInitialVector().buf())
# Assume the algorithmType value is the same as the TLV type.
encoder.writeNonNegativeIntegerTlv(
Tlv.Encrypt_EncryptionAlgorithm, encryptedContent.getAlgorithmType())
Tlv0_1_1WireFormat._encodeKeyLocator(
Tlv.KeyLocator, encryptedContent.getKeyLocator(), encoder)
encoder.writeTypeAndLength(
Tlv.Encrypt_EncryptedContent, len(encoder) - saveLength)
return Blob(encoder.getOutput(), False)
示例3: encodeControlResponse
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeControlResponse(self, controlResponse):
"""
Encode controlResponse and return the encoding.
:param controlResponse: The ControlResponse object to encode.
:type controlResponse: ControlResponse
:return: A Blob containing the encoding.
:rtype: Blob
"""
encoder = TlvEncoder(256)
saveLength = len(encoder)
# Encode backwards.
# Encode the body.
if controlResponse.getBodyAsControlParameters() != None:
self._encodeControlParameters(
controlResponse.getBodyAsControlParameters(), encoder)
encoder.writeBlobTlv(
Tlv.NfdCommand_StatusText, Blob(controlResponse.getStatusText()).buf())
encoder.writeNonNegativeIntegerTlv(
Tlv.NfdCommand_StatusCode, controlResponse.getStatusCode())
encoder.writeTypeAndLength(Tlv.NfdCommand_ControlResponse,
len(encoder) - saveLength)
return Blob(encoder.getOutput(), False)
示例4: encodeDelegationSet
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeDelegationSet(self, delegationSet):
"""
Encode the DelegationSet in NDN-TLV and return the encoding. Note that
the sequence of Delegation does not have an outer TLV type and length
because it is intended to use the type and length of a Data packet's
Content.
:param DelegationSet delegationSet: The DelegationSet object to
encode.
:return: A Blob containing the encoding.
:rtype: Blob
"""
encoder = TlvEncoder(256)
# Encode backwards.
for i in range(delegationSet.size() - 1, -1, -1):
saveLength = len(encoder)
Tlv0_1_1WireFormat._encodeName(delegationSet.get(i).getName(), encoder)
encoder.writeNonNegativeIntegerTlv(
Tlv.Link_Preference, delegationSet.get(i).getPreference())
encoder.writeTypeAndLength(
Tlv.Link_Delegation, len(encoder) - saveLength)
return Blob(encoder.getOutput(), False)
示例5: encodeData
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeData(self, data):
"""
Encode data in NDN-TLV and return the encoding and signed offsets.
:param Data data: The Data object to encode.
:return: 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.
:rtype: (Blob, int, int)
"""
encoder = TlvEncoder(1500)
saveLength = len(encoder)
# Encode backwards.
# TODO: The library needs to handle other signature types than
# SignatureSha256WithRsa.
encoder.writeBlobTlv(Tlv.SignatureValue,
data.getSignature().getSignature().buf())
signedPortionEndOffsetFromBack = len(encoder)
self._encodeSignatureSha256WithRsa(data.getSignature(), encoder)
encoder.writeBlobTlv(Tlv.Content, data.getContent().buf())
self._encodeMetaInfo(data.getMetaInfo(), encoder)
self._encodeName(data.getName(), encoder)
signedPortionBeginOffsetFromBack = len(encoder)
encoder.writeTypeAndLength(Tlv.Data, len(encoder) - saveLength)
signedPortionBeginOffset = (len(encoder) -
signedPortionBeginOffsetFromBack)
signedPortionEndOffset = len(encoder) - signedPortionEndOffsetFromBack
return (Blob(encoder.getOutput(), False), signedPortionBeginOffset,
signedPortionEndOffset)
示例6: wireEncode
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def wireEncode(self):
"""
Encode this Schedule.
:return: The encoded buffer.
:rtype: Blob
"""
# For now, don't use WireFormat and hardcode to use TLV since the
# encoding doesn't go out over the wire, only into the local SQL database.
encoder = TlvEncoder(256)
saveLength = len(encoder)
# Encode backwards.
# Encode the blackIntervalList.
saveLengthForList = len(encoder)
for i in range(len(self._blackIntervalList) - 1, -1, -1):
Schedule._encodeRepetitiveInterval(self._blackIntervalList[i], encoder)
encoder.writeTypeAndLength(Tlv.Encrypt_BlackIntervalList, len(encoder) - saveLengthForList)
# Encode the whiteIntervalList.
saveLengthForList = len(encoder)
for i in range(len(self._whiteIntervalList) - 1, -1, -1):
Schedule._encodeRepetitiveInterval(self._whiteIntervalList[i], encoder)
encoder.writeTypeAndLength(Tlv.Encrypt_WhiteIntervalList, len(encoder) - saveLengthForList)
encoder.writeTypeAndLength(Tlv.Encrypt_Schedule, len(encoder) - saveLength)
return Blob(encoder.getOutput(), False)
示例7: encodeName
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeName(self, name):
"""
Encode name in NDN-TLV and return the encoding.
:param Name name: The Name object to encode.
:return: A Blob containing the encoding.
:rtype: Blob
"""
encoder = TlvEncoder(256)
self._encodeName(name, encoder)
return Blob(encoder.getOutput(), False)
示例8: encodeControlParameters
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeControlParameters(self, controlParameters):
"""
Encode controlParameters and return the encoding.
:param controlParameters: The ControlParameters object to encode.
:type controlParameters: ControlParameters
:return: A Blob containing the encoding.
:rtype: Blob
"""
encoder = TlvEncoder(256)
self._encodeControlParameters(controlParameters, encoder)
return Blob(encoder.getOutput(), False)
示例9: wireEncode
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def wireEncode(self):
# if self.m_wire.hasWire():
# return m_wire;
# EncodingEstimator estimator;
# size_t estimatedSize = wireEncode(estimator);
buffer = TlvEncoder()
# Ummm, this is not how polymorphism should look
self.wireEncodeX(buffer)
output = buffer.getOutput()
return Blob((output), False)
示例10: encodeSignatureInfo
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeSignatureInfo(self, signature):
"""
Encode signature as an NDN-TLV SignatureInfo and return the encoding.
:param signature: An object of a subclass of Signature to encode.
:type signature: An object of a subclass of Signature
:return: A Blob containing the encoding.
:rtype: Blob
"""
encoder = TlvEncoder(256)
self._encodeSignatureInfo(signature, encoder)
return Blob(encoder.getOutput(), False)
示例11: encodeSignatureValue
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeSignatureValue(self, signature):
"""
Encode the signatureValue in the Signature object as an NDN-TLV
SignatureValue (the signature bits) and return the encoding.
:param signature: An object of a subclass of Signature with the
signature value to encode.
:type signature: An object of a subclass of Signature
:return: A Blob containing the encoding.
:rtype: Blob
"""
encoder = TlvEncoder(256)
encoder.writeBlobTlv(Tlv.SignatureValue, signature.getSignature().buf())
return Blob(encoder.getOutput(), False)
示例12: generate
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def generate(self, interest, keyChain, certificateName, wireFormat = None):
"""
Append a timestamp component and a random value component to interest's
name. This ensures that the timestamp is greater than the timestamp used
in the previous call. Then use keyChain to sign the interest which
appends a SignatureInfo component and a component with the signature
bits. If the interest lifetime is not set, this sets it.
:param Interest interest: The interest whose name is append with
components.
:param KeyChain keyChain: The KeyChain for calling sign.
:param Name certificateName: The certificate name of the key to use for
signing.
:param wireFormat: (optional) A WireFormat object used to encode the
SignatureInfo and to encode interest name for signing. If omitted, use
WireFormat.getDefaultWireFormat().
:type wireFormat: A subclass of WireFormat
"""
if wireFormat == None:
# Don't use a default argument since getDefaultWireFormat can change.
wireFormat = WireFormat.getDefaultWireFormat()
timestamp = round(Common.getNowMilliseconds())
while timestamp <= self._lastTimestamp:
timestamp += 1.0
# The timestamp is encoded as a TLV nonNegativeInteger.
encoder = TlvEncoder(8)
encoder.writeNonNegativeInteger(int(timestamp))
interest.getName().append(Blob(encoder.getOutput(), False))
# The random value is a TLV nonNegativeInteger too, but we know it is 8
# bytes, so we don't need to call the nonNegativeInteger encoder.
randomBuffer = bytearray(8)
for i in range(len(randomBuffer)):
randomBuffer[i] = _systemRandom.randint(0, 0xff)
interest.getName().append(Blob(randomBuffer, False))
keyChain.sign(interest, certificateName, wireFormat)
if (interest.getInterestLifetimeMilliseconds() == None or
interest.getInterestLifetimeMilliseconds()< 0):
# The caller has not set the interest lifetime, so set it here.
interest.setInterestLifetimeMilliseconds(1000.0)
# We successfully signed the interest, so update the timestamp.
self._lastTimestamp = timestamp
示例13: encode
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encode(message):
"""
Encode the Protobuf message object as NDN-TLV.
:param google.protobuf.message message: The Protobuf message object.
This calls message.IsInitialized() to ensure that all required fields
are present and raises an exception if not.
:return: The encoded buffer in a Blob object.
:rtype: Blob
"""
if not message.IsInitialized():
raise RuntimeError("message is not initialized")
encoder = TlvEncoder(256)
ProtobufTlv._encodeMessageValue(message, encoder)
return Blob(encoder.getOutput(), False)
示例14: encodeInterest
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeInterest(self, interest):
"""
Encode interest in NDN-TLV and return the encoding.
:param Interest interest: The Interest object to encode.
:return: A Blob containing the encoding.
:rtype: Blob
"""
encoder = TlvEncoder(256)
saveLength = len(encoder)
# Encode backwards.
encoder.writeOptionalNonNegativeIntegerTlvFromFloat(
Tlv.InterestLifetime, interest.getInterestLifetimeMilliseconds())
encoder.writeOptionalNonNegativeIntegerTlv(
Tlv.Scope, interest.getScope())
# Encode the Nonce as 4 bytes.
if interest.getNonce().size() == 0:
# This is the most common case. Generate a nonce.
nonce = bytearray(4)
for i in range(4):
nonce[i] = _systemRandom.randint(0, 0xff)
encoder.writeBlobTlv(Tlv.Nonce, nonce)
elif interest.getNonce().size() < 4:
nonce = bytearray(4)
# Copy existing nonce bytes.
nonce[:interest.getNonce().size()] = interest.getNonce().buf()
# Generate random bytes for remaining bytes in the nonce.
for i in range(interest.getNonce().size(), 4):
nonce[i] = _systemRandom.randint(0, 0xff)
encoder.writeBlobTlv(Tlv.Nonce, nonce)
elif interest.getNonce().size() == 4:
# Use the nonce as-is.
encoder.writeBlobTlv(Tlv.Nonce, interest.getNonce().buf())
else:
# Truncate.
encoder.writeBlobTlv(Tlv.Nonce, interest.getNonce().buf()[:4])
self._encodeSelectors(interest, encoder)
self._encodeName(interest.getName(), encoder)
encoder.writeTypeAndLength(Tlv.Interest, len(encoder) - saveLength)
return Blob(encoder.getOutput(), False)
示例15: encodeControlParameters
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import getOutput [as 别名]
def encodeControlParameters(self, controlParameters):
"""
Encode controlParameters and return the encoding.
:param controlParameters: The ControlParameters object to encode.
:type controlParameters: ControlParameters
:return: A Blob containing the encoding.
:rtype: Blob
"""
encoder = TlvEncoder(256)
saveLength = len(encoder)
# Encode backwards.
encoder.writeOptionalNonNegativeIntegerTlvFromFloat(
Tlv.ControlParameters_ExpirationPeriod,
controlParameters.getExpirationPeriod())
# TODO: Encode Strategy.
flags = controlParameters.getForwardingFlags().getNfdForwardingFlags()
if (flags != ForwardingFlags().getNfdForwardingFlags()):
# The flags are not the default value.
encoder.writeNonNegativeIntegerTlv(
Tlv.ControlParameters_Flags, flags)
encoder.writeOptionalNonNegativeIntegerTlv(
Tlv.ControlParameters_Cost, controlParameters.getCost())
encoder.writeOptionalNonNegativeIntegerTlv(
Tlv.ControlParameters_Origin, controlParameters.getOrigin())
encoder.writeOptionalNonNegativeIntegerTlv(
Tlv.ControlParameters_LocalControlFeature,
controlParameters.getLocalControlFeature())
# TODO: Encode Uri.
encoder.writeOptionalNonNegativeIntegerTlv(
Tlv.ControlParameters_FaceId, controlParameters.getFaceId())
if controlParameters.getName().size() > 0:
self._encodeName(controlParameters.getName(), encoder)
encoder.writeTypeAndLength(Tlv.ControlParameters_ControlParameters,
len(encoder) - saveLength)
return Blob(encoder.getOutput(), False)