本文整理汇总了Python中pyndn.encoding.ProtobufTlv.toName方法的典型用法代码示例。如果您正苦于以下问题:Python ProtobufTlv.toName方法的具体用法?Python ProtobufTlv.toName怎么用?Python ProtobufTlv.toName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.encoding.ProtobufTlv
的用法示例。
在下文中一共展示了ProtobufTlv.toName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processRegisterResponse
# 需要导入模块: from pyndn.encoding import ProtobufTlv [as 别名]
# 或者: from pyndn.encoding.ProtobufTlv import toName [as 别名]
def processRegisterResponse(encodedControlResponse):
"""
This is called when the register route command responds to decode the
encodedControlResponse as a TLV ControlParametersResponse message
containing one ControlParameters. On success, print the ControlParameters
values which should be the same as requested.
:param Blob encodedControlResponse: The TLV-encoded ControlParametersResponse.
"""
decodedControlResponse = \
control_parameters_pb2.ControlParametersTypes.ControlParametersResponseMessage()
ProtobufTlv.decode(decodedControlResponse, encodedControlResponse)
controlResponse = decodedControlResponse.control_response
lowestErrorCode = 400
if controlResponse.status_code >= lowestErrorCode:
dump(
"Face create command got error, code " + str(controlResponse.status_code) +
": " + controlResponse.status_text)
return
if len(controlResponse.control_parameters) != 1:
dump(
"Face create command response does not have one ControlParameters")
return
# Success. Print the ControlParameters response.
controlParameters = controlResponse.control_parameters[0]
dump(
"Successful in name registration: ControlParameters(Name: " +
ProtobufTlv.toName(controlParameters.name.component).toUri() +
", FaceId: " + str(controlParameters.face_id) +
", Origin: " + str(controlParameters.origin) +
", Cost: " + str(controlParameters.cost) +
", Flags: " + str(controlParameters.flags) + ")")
示例2: printRibEntries
# 需要导入模块: from pyndn.encoding import ProtobufTlv [as 别名]
# 或者: from pyndn.encoding.ProtobufTlv import toName [as 别名]
def printRibEntries(encodedMessage):
"""
This is called when all the segments are received to decode the
encodedMessage as repeated TLV RibEntry messages and display the values.
:param Blob encodedMessage: The repeated TLV-encoded RibEntry.
"""
ribEntryMessage = rib_entry_pb2.RibEntryMessage()
ProtobufTlv.decode(ribEntryMessage, encodedMessage)
dump("RIB:");
for ribEntry in ribEntryMessage.rib_entry:
line = ""
line += ProtobufTlv.toName(ribEntry.name.component).toUri()
# Show the routes.
for route in ribEntry.routes:
line += (" route={faceId=" + str(route.face_id) + " (origin=" +
str(route.origin) + " cost=" + str(route.cost))
if (route.flags & 1) != 0:
line += " ChildInherit"
if (route.flags & 2) != 0:
line += " Capture"
if route.HasField("expiration_period"):
line += " expirationPeriod=" + str(route.expiration_period)
line += ")}"
dump(line)
示例3: main
# 需要导入模块: from pyndn.encoding import ProtobufTlv [as 别名]
# 或者: from pyndn.encoding.ProtobufTlv import toName [as 别名]
def main():
# Construct a sample FibEntry message using the structure in fib_entry_pb2
# which was produced by protoc.
message = fib_entry_pb2.FibEntryMessage()
message.fib_entry.name.component.append(b"ndn")
message.fib_entry.name.component.append(b"ucla")
nextHopRecord = message.fib_entry.next_hop_records.add()
nextHopRecord.face_id = 16
nextHopRecord.cost = 1
# Encode the Protobuf message object as TLV.
encoding = ProtobufTlv.encode(message)
decodedMessage = fib_entry_pb2.FibEntryMessage()
ProtobufTlv.decode(decodedMessage, encoding)
dump("Re-decoded FibEntry:")
# This should print the same values that we put in message above.
value = ""
value += ProtobufTlv.toName(decodedMessage.fib_entry.name.component).toUri()
value += " nexthops = {"
for next_hop_record in decodedMessage.fib_entry.next_hop_records:
value += ("faceid=" + repr(next_hop_record.face_id)
+ " (cost=" + repr(next_hop_record.cost) + ")")
value += " }"
dump(value)