本文整理汇总了Python中pyndn.encoding.tlv.tlv_encoder.TlvEncoder.writeNonNegativeInteger方法的典型用法代码示例。如果您正苦于以下问题:Python TlvEncoder.writeNonNegativeInteger方法的具体用法?Python TlvEncoder.writeNonNegativeInteger怎么用?Python TlvEncoder.writeNonNegativeInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.encoding.tlv.tlv_encoder.TlvEncoder
的用法示例。
在下文中一共展示了TlvEncoder.writeNonNegativeInteger方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import writeNonNegativeInteger [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
示例2: prepareCommandInterestName
# 需要导入模块: from pyndn.encoding.tlv.tlv_encoder import TlvEncoder [as 别名]
# 或者: from pyndn.encoding.tlv.tlv_encoder.TlvEncoder import writeNonNegativeInteger [as 别名]
def prepareCommandInterestName(self, interest, wireFormat = None):
"""
Append a timestamp component and a random nonce component to interest's
name. This ensures that the timestamp is greater than the timestamp used
in the previous call.
:param Interest interest: The interest whose name is append with
components.
:param WireFormat wireFormat: (optional) A WireFormat object used to
encode the SignatureInfo. If omitted, use WireFormat
getDefaultWireFormat().
"""
if wireFormat == None:
wireFormat = WireFormat.getDefaultWireFormat()
# _nowOffsetMilliseconds is only used for testing.
now = Common.getNowMilliseconds() + self._nowOffsetMilliseconds
timestamp = round(now)
while timestamp <= self._lastUsedTimestamp:
timestamp += 1.0
# Update the timestamp now. In the small chance that signing fails, it
# just means that we have bumped the timestamp.
self._lastUsedTimestamp = timestamp
# 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))