本文整理汇总了Python中google.protobuf.internal.decoder._DecodeVarint方法的典型用法代码示例。如果您正苦于以下问题:Python decoder._DecodeVarint方法的具体用法?Python decoder._DecodeVarint怎么用?Python decoder._DecodeVarint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.protobuf.internal.decoder
的用法示例。
在下文中一共展示了decoder._DecodeVarint方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _read_varint
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def _read_varint(self):
"""Read a varint from file, parse it, and return the decoded integer.
"""
buff = self._fd.read(1)
if buff == b'':
return 0
while (bytearray(buff)[-1] & 0x80) >> 7 == 1: # while the MSB is 1
new_byte = self._fd.read(1)
if new_byte == b'':
raise EOFError('unexpected EOF.')
buff += new_byte
varint, _ = decodeVarint(buff, 0)
return varint
示例2: _async_read_varint
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def _async_read_varint(self):
"""Read a varint from an async stream, parse it, and return the decoded
integer.
"""
buff = await self._fd.read(1)
if buff == b'':
return 0
while (bytearray(buff)[-1] & 0x80) >> 7 == 1: # while the MSB is 1
new_byte = await self._fd.read(1)
if new_byte == b'':
raise EOFError('unexpected EOF.')
buff += new_byte
varint, _ = decodeVarint(buff, 0)
return varint
示例3: annotate_proto
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def annotate_proto(self, text, annotators=None):
"""Return a Document protocol buffer from the CoreNLP server, containing annotations of the text.
:param (str) text: text to be annotated
:param (list[str]) annotators: a list of annotator names
:return (CoreNLP_pb2.Document): a Document protocol buffer
"""
properties = {
'annotators': ','.join(annotators or self.default_annotators),
'outputFormat': 'serialized',
'serializer': 'edu.stanford.nlp.pipeline.ProtobufAnnotationSerializer'
}
r = self._request(text, properties)
buffer = r.content # bytes
size, pos = _DecodeVarint(buffer, 0)
buffer = buffer[pos:(pos + size)]
doc = CoreNLP_pb2.Document()
doc.ParseFromString(buffer)
return doc
示例4: ReadVarint
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def ReadVarint(self):
result, self._pos = decoder._DecodeVarint(self._bytes, self._pos)
return result
示例5: decode
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def decode(input_file):
"""Output the decoded value to the standard output.
Args:
input_file (file handler): input file handler.
"""
print(decodeVarint(input_file.read(), 0)[0])
示例6: UnPack
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def UnPack(src, key=b''):
if len(src) < 0x20:
raise RuntimeError('Unpack Error!Please check mm protocol!') # 协议需要更新
return b''
if not key:
key = Util.sessionKey
# 解析包头
nCur = 0
if src[nCur] == struct.unpack('>B', b'\xbf')[0]:
nCur += 1 # 跳过协议标志位
nLenHeader = src[nCur] >> 2 # 包头长度
bUseCompressed = (src[nCur] & 0x3 == 1) # 包体是否使用压缩算法:01使用,02不使用
nCur += 1
nDecryptType = src[nCur] >> 4 # 解密算法(固定为AES解密): 05 aes解密 / 07 rsa解密
nLenCookie = src[nCur] & 0xf # cookie长度
nCur += 1
nCur += 4 # 服务器版本(当前固定返回4字节0)
uin = struct.unpack('>i', src[nCur:nCur+4])[0] # uin
nCur += 4
cookie_temp = src[nCur:nCur+nLenCookie] # cookie
if cookie_temp and not(cookie_temp == Util.cookie):
Util.cookie = cookie_temp # 刷新cookie
nCur += nLenCookie
(nCgi, nCur) = decoder._DecodeVarint(src, nCur) # cgi type
(nLenProtobuf, nCur) = decoder._DecodeVarint(src, nCur) # 压缩前protobuf长度
(nLenCompressed, nCur) = decoder._DecodeVarint(src, nCur) # 压缩后protobuf长度
logger.debug('包头长度:{}\n是否使用压缩算法:{}\n解密算法:{}\ncookie长度:{}\nuin:{}\ncookie:{}\ncgi type:{}\nprotobuf长度:{}\n压缩后protobuf长度:{}'.format(
nLenHeader, bUseCompressed, nDecryptType, nLenCookie, uin, str(Util.cookie), nCgi, nLenProtobuf, nLenCompressed))
# 对包体aes解密解压缩
body = src[nLenHeader:] # 取包体数据
if bUseCompressed:
protobufData = Util.decompress_and_aesDecrypt(body, key)
else:
protobufData = Util.aesDecrypt(body, key)
logger.debug('解密后数据:%s' % str(protobufData))
return protobufData
# 登录组包函数
示例7: set_group_nick_name_buf2resp
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def set_group_nick_name_buf2resp(buf):
res = mm_pb2.oplog_resp()
res.ParseFromString(UnPack(buf))
try:
code,__ = decoder._DecodeVarint(res.res.code, 0)
if code:
logger.info('设置群昵称失败,错误码:0x{:x},错误信息:{}'.format(code, res.res.msg), 11)
except:
code = -1
logger.info('设置群昵称失败!', 11)
return code
# 消息撤回请求
示例8: op_friend_buf2resp
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def op_friend_buf2resp(buf):
res = mm_pb2.oplog_resp()
res.ParseFromString(UnPack(buf))
try:
code,__ = decoder._DecodeVarint(res.res.code, 0)
if code:
logger.info('好友操作失败,错误码:0x{:x},错误信息:{}'.format(code, res.res.msg), 11)
except:
code = -1
logger.info('好友操作失败!', 11)
return code
# 发布群公告请求(仅限群主;自动@所有人)
示例9: unpack
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def unpack(data):
'''unpack from delimited data'''
size, position = decoder._DecodeVarint(data, 0)
envelope = wire.Envelope()
envelope.ParseFromString(data[position:position+size])
return envelope
示例10: decode_uvarint
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def decode_uvarint(buf, pos):
"""Decode bytearray into a long."""
# Convert buffer to string
buf = buf.decode('latin')
value, pos = decoder._DecodeVarint(buf, pos)
return (value, pos)
示例11: from_bytes
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def from_bytes(bytes_):
offset = 0
doc = Document()
size, pos = _DecodeVarint(bytes_, offset)
doc.ParseFromString(bytes_[offset + pos:offset + pos + size])
return doc
示例12: decode_uvarint
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def decode_uvarint(buf, pos):
"""Decode bytearray into a long."""
# Convert buffer to string
# buf = buf.decode('latin')
value, pos = decoder._DecodeVarint(buf, pos)
return value, pos
示例13: decode_uvarint
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def decode_uvarint(buf, pos):
"""Decode bytearray into a long."""
# Convert buffer to string
#buf = buf.decode('latin')
value, pos = decoder._DecodeVarint(buf, pos)
return (value, pos)
示例14: walk_binary
# 需要导入模块: from google.protobuf.internal import decoder [as 别名]
# 或者: from google.protobuf.internal.decoder import _DecodeVarint [as 别名]
def walk_binary(binr):
if type(binr) == str:
try:
with open(binr, 'rb') as fd:
binr = fd.read()
except Exception:
return
# Search for:
# ".proto" or ".protodevel", as part of the "name" (1) field
cursor = 0
while cursor < len(binr):
cursor = binr.find(b'.proto', cursor)
if cursor == -1:
break
cursor += len('.proto')
cursor += (binr[cursor:cursor + 5] == b'devel') * 5
# Search back for the (1, length-delimited) marker
start = binr.rfind(b'\x0a', max(cursor - 1024, 0), cursor)
if start > 0 and binr[start - 1] == 0x0a == (cursor - start - 1):
start -= 1
# Check whether length byte is coherent
if start == -1:
continue
varint, end = _DecodeVarint(binr, start + 1)
if cursor - end != varint:
continue
# Look just after for subsequent markers
tags = b'\x12\x1a\x22\x2a\x32\x3a\x42\x4a\x50\x58\x62'
if binr[cursor] not in tags:
continue
while cursor < len(binr) and binr[cursor] in tags:
tags = tags[tags.index(binr[cursor]):]
varint, end = _DecodeVarint(binr, cursor + 1)
cursor = end + varint * (binr[cursor] & 0b111 == 2)
# Parse descriptor
proto = FileDescriptorProto()
proto.ParseFromString(binr[start:cursor])
# Convert to ascii
yield descpb_to_proto(proto)