本文整理汇总了Python中thriftpy.transport.TMemoryBuffer.getvalue方法的典型用法代码示例。如果您正苦于以下问题:Python TMemoryBuffer.getvalue方法的具体用法?Python TMemoryBuffer.getvalue怎么用?Python TMemoryBuffer.getvalue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thriftpy.transport.TMemoryBuffer
的用法示例。
在下文中一共展示了TMemoryBuffer.getvalue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: thrift_obj_in_bytes
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
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())
示例2: test_write_string
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
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())
示例3: test_pack_string
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
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())
示例4: test_write_bool
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
def test_write_bool():
b = TMemoryBuffer()
b = TCyBufferedTransport(b)
proto.write_val(b, TType.BOOL, 1)
b.flush()
assert "01" == hexlify(b.getvalue())
示例5: test_write_i8
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
def test_write_i8():
b = TMemoryBuffer()
b = TCyBufferedTransport(b)
proto.write_val(b, TType.I08, 123)
b.flush()
assert "7b" == hexlify(b.getvalue())
示例6: test_write_i16
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
def test_write_i16():
b = TMemoryBuffer()
b = TCyBufferedTransport(b)
proto.write_val(b, TType.I16, 12345)
b.flush()
assert "30 39" == hexlify(b.getvalue())
示例7: test_write_i32
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
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())
示例8: test_write_empty_struct
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
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())
示例9: test_write_message_begin
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
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())
示例10: test_write_struct
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
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())
示例11: thrift_obj_in_bytes
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
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())
示例12: test_json_proto_api_write
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
def test_json_proto_api_write():
obj = TItem(id=13, phones=["5234", "12346456"])
trans = TMemoryBuffer()
p = TJSONProtocol(trans)
p.write_struct(obj)
data = trans.getvalue().decode("utf-8")
length = data[0:4]
import json
data = json.loads(data[4:])
assert length == "\x00\x00\x00S" and data == {
"metadata": {"version": 1},
"payload": {"phones": ["5234", "12346456"], "id": 13}}
示例13: test_write_i64
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
def test_write_i64():
b = TMemoryBuffer()
b = TCyBufferedTransport(b)
proto.write_val(b, TType.I64, 1234567890123456789)
b.flush()
assert "11 22 10 f4 7d e9 81 15" == hexlify(b.getvalue())
示例14: test_pack_i16
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
def test_pack_i16():
b = TMemoryBuffer()
p = proto.TCyBinaryProtocol(b)
p.write_val(TType.I16, 12345)
p.write_message_end()
assert "30 39" == hexlify(b.getvalue())
示例15: test_pack_i8
# 需要导入模块: from thriftpy.transport import TMemoryBuffer [as 别名]
# 或者: from thriftpy.transport.TMemoryBuffer import getvalue [as 别名]
def test_pack_i8():
b = TMemoryBuffer()
p = proto.TCyBinaryProtocol(b)
p.write_val(TType.I08, 123)
p.write_message_end()
assert "7b" == hexlify(b.getvalue())