本文整理汇总了Python中pyndn.data.Data.setLpPacket方法的典型用法代码示例。如果您正苦于以下问题:Python Data.setLpPacket方法的具体用法?Python Data.setLpPacket怎么用?Python Data.setLpPacket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.data.Data
的用法示例。
在下文中一共展示了Data.setLpPacket方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onReceivedElement
# 需要导入模块: from pyndn.data import Data [as 别名]
# 或者: from pyndn.data.Data import setLpPacket [as 别名]
def onReceivedElement(self, element):
"""
This is called by the transport's ElementReader to process an
entire received Data or Interest element.
:param element: The bytes of the incoming element.
:type element: An array type with int elements
"""
lpPacket = None
if element[0] == Tlv.LpPacket_LpPacket:
# Decode the LpPacket and replace element with the fragment.
lpPacket = LpPacket()
# Set copy False so that the fragment is a slice which will be
# copied below. The header fields are all integers and don't need to
# be copied.
TlvWireFormat.get().decodeLpPacket(lpPacket, element, False)
element = lpPacket.getFragmentWireEncoding().buf()
# First, decode as Interest or Data.
data = None
decoder = TlvDecoder(element)
if decoder.peekType(Tlv.Data, len(element)):
data = Data()
data.wireDecode(element, TlvWireFormat.get())
if lpPacket != None:
data.setLpPacket(lpPacket)
# Now process as Interest or Data.
if data != None:
if self._onBtleData:
self._onBtleData(data)
示例2: onReceivedElement
# 需要导入模块: from pyndn.data import Data [as 别名]
# 或者: from pyndn.data.Data import setLpPacket [as 别名]
def onReceivedElement(self, element):
"""
This is called by the transport's ElementReader to process an
entire received Data or Interest element.
:param element: The bytes of the incoming element.
:type element: An array type with int elements
"""
lpPacket = None
if element[0] == Tlv.LpPacket_LpPacket:
# Decode the LpPacket and replace element with the fragment.
lpPacket = LpPacket()
# Set copy False so that the fragment is a slice which will be
# copied below. The header fields are all integers and don't need to
# be copied.
TlvWireFormat.get().decodeLpPacket(lpPacket, element, False)
element = lpPacket.getFragmentWireEncoding().buf()
# First, decode as Interest or Data.
interest = None
data = None
decoder = TlvDecoder(element)
if decoder.peekType(Tlv.Interest, len(element)):
interest = Interest()
interest.wireDecode(element, TlvWireFormat.get())
if lpPacket != None:
interest.setLpPacket(lpPacket)
elif decoder.peekType(Tlv.Data, len(element)):
data = Data()
data.wireDecode(element, TlvWireFormat.get())
if lpPacket != None:
data.setLpPacket(lpPacket)
if lpPacket != None:
# We have decoded the fragment, so remove the wire encoding to save
# memory.
lpPacket.setFragmentWireEncoding(Blob())
networkNack = NetworkNack.getFirstHeader(lpPacket)
if networkNack != None:
if interest == None:
# We got a Nack but not for an Interest, so drop the packet.
return
pendingInterests = []
self._pendingInterestTable.extractEntriesForNackInterest(
interest, pendingInterests)
for pendingInterest in pendingInterests:
try:
pendingInterest.getOnNetworkNack()(
pendingInterest.getInterest(), networkNack)
except:
logging.exception("Error in onNetworkNack")
# We have processed the network Nack packet.
return
# Now process as Interest or Data.
if interest != None:
self._dispatchInterest(interest)
elif data != None:
self._satisfyPendingInterests(data)