當前位置: 首頁>>代碼示例>>Python>>正文


Python transport.TMemoryBuffer類代碼示例

本文整理匯總了Python中thriftpy.transport.TMemoryBuffer的典型用法代碼示例。如果您正苦於以下問題:Python TMemoryBuffer類的具體用法?Python TMemoryBuffer怎麽用?Python TMemoryBuffer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TMemoryBuffer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_write_bool

def test_write_bool():
    b = TMemoryBuffer()
    b = TCyBufferedTransport(b)
    proto.write_val(b, TType.BOOL, 1)
    b.flush()

    assert "01" == hexlify(b.getvalue())
開發者ID:lepture,項目名稱:thriftpy,代碼行數:7,代碼來源:test_protocol_cybinary.py

示例2: test_write_empty_struct

def test_write_empty_struct():
    b = TMemoryBuffer()
    item = TItem()
    p = proto.TCyBinaryProtocol(b)
    p.write_struct(item)
    p.write_message_end()
    assert "00" == hexlify(b.getvalue())
開發者ID:lodevil,項目名稱:thriftpy,代碼行數:7,代碼來源:test_protocol_cybinary.py

示例3: test_write_i8

def test_write_i8():
    b = TMemoryBuffer()
    b = TCyBufferedTransport(b)
    proto.write_val(b, TType.I08, 123)
    b.flush()

    assert "7b" == hexlify(b.getvalue())
開發者ID:lepture,項目名稱:thriftpy,代碼行數:7,代碼來源:test_protocol_cybinary.py

示例4: test_pack_string

def test_pack_string():
    b = TMemoryBuffer()
    p = proto.TCyBinaryProtocol(b)
    p.write_val(TType.STRING, "hello world!")
    p.write_message_end()
    assert "00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21" == \
        hexlify(b.getvalue())

    b = TMemoryBuffer()
    p = proto.TCyBinaryProtocol(b)
    p.write_val(TType.STRING, u("你好世界"))
    p.write_message_end()
    assert "00 00 00 0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c" == \
        hexlify(b.getvalue())
開發者ID:lodevil,項目名稱:thriftpy,代碼行數:14,代碼來源:test_protocol_cybinary.py

示例5: test_write_message_begin

def test_write_message_begin():
    b = TMemoryBuffer()
    p = proto.TCyBinaryProtocol(b)
    p.write_message_begin("test", TType.STRING, 1)
    p.write_message_end()
    assert "80 01 00 0b 00 00 00 04 74 65 73 74 00 00 00 01" == \
        hexlify(b.getvalue())
開發者ID:lodevil,項目名稱:thriftpy,代碼行數:7,代碼來源:test_protocol_cybinary.py

示例6: test_write_i32

def test_write_i32():
    b = TMemoryBuffer()
    b = TCyBufferedTransport(b)
    proto.write_val(b, TType.I32, 1234567890)
    b.flush()

    assert "49 96 02 d2" == hexlify(b.getvalue())
開發者ID:lepture,項目名稱:thriftpy,代碼行數:7,代碼來源:test_protocol_cybinary.py

示例7: test_write_i16

def test_write_i16():
    b = TMemoryBuffer()
    b = TCyBufferedTransport(b)
    proto.write_val(b, TType.I16, 12345)
    b.flush()

    assert "30 39" == hexlify(b.getvalue())
開發者ID:lepture,項目名稱:thriftpy,代碼行數:7,代碼來源:test_protocol_cybinary.py

示例8: test_write_message_begin_no_strict

def test_write_message_begin_no_strict():
    b = TMemoryBuffer()
    trans = TCyBufferedTransport(b)
    b = proto.TCyBinaryProtocol(trans, strict_write=False)
    b.write_message_begin("test", TType.STRING, 1)
    b.write_message_end()
    assert "00 00 00 04 74 65 73 74 0b 00 00 00 01" == \
        hexlify(trans.getvalue())
開發者ID:lepture,項目名稱:thriftpy,代碼行數:8,代碼來源:test_protocol_cybinary.py

示例9: test_write_empty_struct

def test_write_empty_struct():
    b = TMemoryBuffer()
    trans = TCyBufferedTransport(b)
    b = proto.TCyBinaryProtocol(trans)
    item = TItem()
    b.write_struct(item)
    b.write_message_end()
    assert "00" == hexlify(trans.getvalue())
開發者ID:lepture,項目名稱:thriftpy,代碼行數:8,代碼來源:test_protocol_cybinary.py

示例10: test_read_empty_struct

def test_read_empty_struct():
    b = TMemoryBuffer(b"\x00")
    b = TCyBufferedTransport(b)
    b = proto.TCyBinaryProtocol(b)
    _item = TItem()
    _item2 = TItem()
    b.read_struct(_item2)
    assert _item == _item2
開發者ID:lepture,項目名稱:thriftpy,代碼行數:8,代碼來源:test_protocol_cybinary.py

示例11: test_read_struct

def test_read_struct():
    b = TMemoryBuffer(b"\x08\x00\x01\x00\x00\x00{\x0f\x00\x02\x0b\x00\x00\x00"
                      b"\x02\x00\x00\x00\x06123456\x00\x00\x00\x06abcdef\x00")
    b = TCyBufferedTransport(b)
    b = proto.TCyBinaryProtocol(b)
    _item = TItem(id=123, phones=["123456", "abcdef"])
    _item2 = TItem()
    b.read_struct(_item2)
    assert _item == _item2
開發者ID:lepture,項目名稱:thriftpy,代碼行數:9,代碼來源:test_protocol_cybinary.py

示例12: test_write_struct

def test_write_struct():
    b = TMemoryBuffer()
    item = TItem(id=123, phones=["123456", "abcdef"])
    p = proto.TCyBinaryProtocol(b)
    p.write_struct(item)
    p.write_message_end()
    assert ("08 00 01 00 00 00 7b 0f 00 02 0b 00 00 00 02 00 00 00 "
            "06 31 32 33 34 35 36 00 00 00 06 61 62 63 64 65 66 00") == \
        hexlify(b.getvalue())
開發者ID:lodevil,項目名稱:thriftpy,代碼行數:9,代碼來源:test_protocol_cybinary.py

示例13: thrift_obj_in_bytes

def thrift_obj_in_bytes(thrift_obj):  # pragma: no cover
    """
    Returns TBinaryProtocol encoded Thrift object.

    :param thrift_obj: thrift object to encode
    :returns: thrift object in TBinaryProtocol format bytes.
    """
    trans = TMemoryBuffer()
    thrift_obj.write(TBinaryProtocol(trans))

    return bytes(trans.getvalue())
開發者ID:adriancole,項目名稱:pyramid_zipkin,代碼行數:11,代碼來源:thrift_helper.py

示例14: thrift_obj_in_bytes

def thrift_obj_in_bytes(thrift_obj): 
    """
    Encodes a Thrift object using TBinaryProtocol.

    :param thrift_obj
    :returns: TBinaryProtocol bytes represenation of thrift_obj.
    """
    trans = TMemoryBuffer()
    thrift_obj.write(TBinaryProtocol(trans))
    return trans.getvalue();
    return bytes(trans.getvalue())
開發者ID:vears91,項目名稱:babeltrace-zipkin,代碼行數:11,代碼來源:thriftpy_utils.py

示例15: test_write_string

def test_write_string():
    b = TMemoryBuffer()
    b = TCyBufferedTransport(b)
    proto.write_val(b, TType.STRING, "hello world!")
    b.flush()
    assert "00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21" == \
        hexlify(b.getvalue())

    b = TMemoryBuffer()
    b = TCyBufferedTransport(b)
    proto.write_val(b, TType.STRING, u("你好世界"))
    b.flush()
    assert "00 00 00 0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c" == \
        hexlify(b.getvalue())
開發者ID:lepture,項目名稱:thriftpy,代碼行數:14,代碼來源:test_protocol_cybinary.py


注:本文中的thriftpy.transport.TMemoryBuffer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。