本文整理汇总了Python中BinaryProtocol.BinaryProtocol类的典型用法代码示例。如果您正苦于以下问题:Python BinaryProtocol类的具体用法?Python BinaryProtocol怎么用?Python BinaryProtocol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryProtocol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync
def sync(self):
println(bp.getProtocolString(bp.SYNC))
# this should block now until we get a response
line = readLine()
if line != (bp.getProtocolString(bp.SYNC) + "_SUCCESS"):
raise RuntimeError(
"Barrier sync failed!")
示例2: initialize
def initialize(self):
"""
INIT protocol works as follows:
START OP_CODE
PROTOCOL_NUMBER
SET_BSPJOB_CONF OP_CODE
NUMBER OF CONF ITEMS (#KEY + #VALUES)
N-LINES, where line is key and the following the value
"""
# parse our initial values
line = readLine()
# start code is the first
if line == bp.getProtocolString(bp.START):
# check the protocol compatibility
protocolNumber = int(readLine())
if protocolNumber != self.PROTOCOL_VERSION:
raise RuntimeError(
"Protocol version mismatch: Expected: " + str(self.PROTOCOL_VERSION) +
" but got: " + str(protocolNumber))
line = readLine()
# parse the configurations
if line == bp.getProtocolString(bp.SET_BSPJOB_CONF):
numberOfItems = readLine()
key = None
value = None
for i in range(0, int(numberOfItems), 2):
key = readLine()
value = readLine()
self.config.put(key, value)
self.ack(bp.START)
示例3: readNext
def readNext(self):
println(bp.getProtocolString(bp.READ_KEYVALUE))
line = readLine()
secondLine = readLine()
# if no message is send it will send %%-1%%
if line == "%%-1%%" and secondLine == "%%-1%%":
return False
return [line, secondLine]
示例4: getAllPeerNames
def getAllPeerNames(self):
println(bp.getProtocolString(bp.GET_ALL_PEERNAME))
ln = readLine()
names = []
for i in range(int(ln)):
peerName = readLine()
names.append(peerName)
return names
示例5: getCurrentMessage
def getCurrentMessage(self):
println(bp.getProtocolString(bp.GET_MSG))
line = readLine()
# if no message is send it will send %%-1%%
if line == "%%-1%%":
return False
return line;
示例6: getCurrentMessage
def getCurrentMessage(self):
println(bp.getProtocolString(bp.GET_MSG))
line = readLine()
# if no message is send it will send %%-1%%
if line == "%%-1%%":
return False
# TODO
# Problem reported by Roman:
# If I send any message of the length L, I receive the message with
# additional (L-1)/2 '^@' symbols after it.
# return line;
return line[:len(line)-len(line)//3]
示例7: send
def send(self, peer, msg):
println(bp.getProtocolString(bp.SEND_MSG))
println(peer)
println(msg)
示例8: log
def log(self, msg):
println(bp.getProtocolString(bp.LOG) + msg)
示例9: done
def done(self):
println(bp.getProtocolString(bp.TASK_DONE))
println(bp.getProtocolString(bp.DONE))
示例10: ack
def ack(self, code):
println(bp.getAckProtocolString(code))
示例11: getPeerNameForIndex
def getPeerNameForIndex(self, index):
println(bp.getProtocolString(bp.GET_PEERNAME))
println(str(index));
return readLine()
示例12: reopenInput
def reopenInput(self):
println(bp.getProtocolString(bp.REOPEN_INPUT))
示例13: write
def write(self, key, value):
println(bp.getProtocolString(bp.WRITE_KEYVALUE))
println(key)
println(value)
示例14: clear
def clear(self):
println(bp.getProtocolString(bp.CLEAR))
示例15: getNumPeers
def getNumPeers(self):
println(bp.getProtocolString(bp.GET_PEER_COUNT))
return readLine()