当前位置: 首页>>代码示例>>Python>>正文


Python TMemoryBuffer._buffer方法代码示例

本文整理汇总了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))
开发者ID:lowks,项目名称:scales,代码行数:47,代码来源:serializer.py

示例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()
开发者ID:lowks,项目名称:scales,代码行数:25,代码来源:serializer.py


注:本文中的thrift.transport.TTransport.TMemoryBuffer._buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。