本文整理汇总了Python中thrift.transport.TTransport.TMemoryBuffer._buffer方法的典型用法代码示例。如果您正苦于以下问题:Python TMemoryBuffer._buffer方法的具体用法?Python TMemoryBuffer._buffer怎么用?Python TMemoryBuffer._buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thrift.transport.TTransport.TMemoryBuffer
的用法示例。
在下文中一共展示了TMemoryBuffer._buffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DeserializeThriftCall
# 需要导入模块: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
# 或者: from thrift.transport.TTransport.TMemoryBuffer import _buffer [as 别名]
def DeserializeThriftCall(self, buf):
"""Deserialize a stream and context to a MethodReturnMessage.
Args:
buf - The buffer.
ctx - The context from serialization.
Returns:
A MethodCallMessage.
"""
thrift_buffer = TMemoryBuffer()
thrift_buffer._buffer = buf
protocol = self._protocol_factory.getProtocol(thrift_buffer)
(fn_name, msg_type, seq_id) = protocol.readMessageBegin()
if msg_type == TMessageType.EXCEPTION:
x = TApplicationException()
x.read(protocol)
protocol.readMessageEnd()
return MethodReturnMessage(error=x)
result_cls = self._FindClass('%s_result' % fn_name)
if result_cls:
result = result_cls()
result.read(protocol)
else:
result = None
protocol.readMessageEnd()
if not result:
return MethodReturnMessage()
if getattr(result, 'success', None) is not None:
return MethodReturnMessage(return_value=result.success)
result_spec = getattr(result_cls, 'thrift_spec', None)
if result_spec:
exceptions = result_spec[1:]
for e in exceptions:
attr_val = getattr(result, e[2], None)
if attr_val is not None:
return MethodReturnMessage(error=attr_val)
return MethodReturnMessage(TApplicationException(
TApplicationException.MISSING_RESULT, "%s failed: unknown result" % fn_name))
示例2: SerializeThriftCall
# 需要导入模块: from thrift.transport.TTransport import TMemoryBuffer [as 别名]
# 或者: from thrift.transport.TTransport.TMemoryBuffer import _buffer [as 别名]
def SerializeThriftCall(self, msg, buf):
"""Serialize a MethodCallMessage to a stream
Args:
msg - The MethodCallMessage to serialize.
buf - The buffer to serialize into.
"""
thrift_buffer = TMemoryBuffer()
thrift_buffer._buffer = buf
protocol = self._protocol_factory.getProtocol(thrift_buffer)
method, args, kwargs = msg.method, msg.args, msg.kwargs
is_one_way = self._FindClass('%s_result' % method) is None
args_cls = self._FindClass('%s_args' % method)
if not args_cls:
raise AttributeError('Unable to find args class for method %s' % method)
protocol.writeMessageBegin(
msg.method,
TMessageType.ONEWAY if is_one_way else TMessageType.CALL,
self._seq_id)
thrift_args = args_cls(*args, **kwargs)
thrift_args.write(protocol)
protocol.writeMessageEnd()