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


Python THeaderTransport.set_max_frame_size方法代码示例

本文整理汇总了Python中thrift.transport.THeaderTransport.THeaderTransport.set_max_frame_size方法的典型用法代码示例。如果您正苦于以下问题:Python THeaderTransport.set_max_frame_size方法的具体用法?Python THeaderTransport.set_max_frame_size怎么用?Python THeaderTransport.set_max_frame_size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thrift.transport.THeaderTransport.THeaderTransport的用法示例。


在下文中一共展示了THeaderTransport.set_max_frame_size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: round_robin

# 需要导入模块: from thrift.transport.THeaderTransport import THeaderTransport [as 别名]
# 或者: from thrift.transport.THeaderTransport.THeaderTransport import set_max_frame_size [as 别名]
    def round_robin(self, compress=None):
        original = b'A' * MAX_FRAME_SIZE
        mb = TMemoryBuffer()
        trans = THeaderTransport(mb, client_type=CLIENT_TYPE.HEADER)
        trans.set_max_frame_size(MAX_FRAME_SIZE + MIN_HEADER_SIZE)
        if compress:
            trans.add_transform(compress)
        trans.write(original)
        trans.flush()
        frame = mb.getvalue()
        # Cleanup the memory buffer
        mb.close()
        del mb

        if compress is None:
            # Partial Decode the frame and see if its correct size wise
            sz = struct.unpack('!I', frame[:4])[0]
            self.assertEqual(sz, BIG_FRAME_MAGIC)
            sz = struct.unpack('!Q', frame[4:12])[0]
            self.assertEqual(len(frame), sz + 12)

        # Read it back
        mb = TMemoryBuffer(frame)
        trans = THeaderTransport(mb, client_type=CLIENT_TYPE.HEADER)
        trans.set_max_frame_size(len(frame))
        trans.readFrame(0)
        result = trans.read(MAX_FRAME_SIZE)
        mb.close()
        del mb
        self.assertEqual(result, original, 'round-robin different from original')
开发者ID:facebook,项目名称:fbthrift,代码行数:32,代码来源:big_frame.py

示例2: TestEof

# 需要导入模块: from thrift.transport.THeaderTransport import THeaderTransport [as 别名]
# 或者: from thrift.transport.THeaderTransport.THeaderTransport import set_max_frame_size [as 别名]
class TestEof(unittest.TestCase):

    def setUp(self):
        self.trans = TTransport.TMemoryBuffer()
        self.trans = THeaderTransport(self.trans)
        self.prot = TBinaryProtocol.TBinaryProtocol(self.trans)

        self.x = Xtruct()
        self.x.string_thing = "Zero"
        self.x.byte_thing = 0

    def testOversizeFrameRecv(self):
        """Test that an oversize frame on recv gets a TTransportException"""

        self.trans.set_max_frame_size(200)

        self.x.write(self.prot)
        self.trans.flush()

        inTrans = TTransport.TMemoryBuffer(self.trans.getTransport().getvalue())
        inTrans = THeaderTransport(inTrans)
        inProt = TBinaryProtocol.TBinaryProtocol(inTrans)

        inTrans.set_max_frame_size(2)

        try:
            self.x.read(inProt)
        except TTransport.TTransportException:
            return

        self.fail("Should have gotten TTransportException")

    def testOversizeFrameSend(self):
        """Test that an oversize frame on send gets a TTransportException"""
        self.trans.set_max_frame_size(2)

        self.x.write(self.prot)

        try:
            self.trans.flush()
        except TTransport.TTransportException:
            return

        self.fail("Should have gotten TTransportException")
开发者ID:343829084,项目名称:fbthrift,代码行数:46,代码来源:TestFrameSize.py

示例3: testOversizeFrameRecv

# 需要导入模块: from thrift.transport.THeaderTransport import THeaderTransport [as 别名]
# 或者: from thrift.transport.THeaderTransport.THeaderTransport import set_max_frame_size [as 别名]
    def testOversizeFrameRecv(self):
        """Test that an oversize frame on recv gets a TTransportException"""

        self.trans.set_max_frame_size(200)

        self.x.write(self.prot)
        self.trans.flush()

        inTrans = TTransport.TMemoryBuffer(self.trans.getTransport().getvalue())
        inTrans = THeaderTransport(inTrans)
        inProt = TBinaryProtocol.TBinaryProtocol(inTrans)

        inTrans.set_max_frame_size(2)

        try:
            self.x.read(inProt)
        except TTransport.TTransportException:
            return

        self.fail("Should have gotten TTransportException")
开发者ID:343829084,项目名称:fbthrift,代码行数:22,代码来源:TestFrameSize.py


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