小编Rti*_*k88的帖子

Apache Thrift Python 3支持

我用以下方法编译了我的test.thrift文件:

thrift -gen py test.thrift
Run Code Online (Sandbox Code Playgroud)

然后我尝试导入创建的文件:

from test.ttypes import *
Run Code Online (Sandbox Code Playgroud)

当我使用Python 2.7时,导入工作,但是使用Python 3.4,它会引发

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/art/SerTest/addressThrift/gen-py/test/ttypes.py", line11, in <module>
from thrift.transport import TTransport
File "/usr/local/lib/python3.4/dist-
packages/thrift/transport/TTransport.py", line 20, in <module>  
from cStringIO import StringIO
ImportError: No module named 'cStringIO'
Run Code Online (Sandbox Code Playgroud)

我试图运行: sudo python3 setup.py install 并且有许多例外,所有似乎都与python 2 vs 3问题有关.例如:

File "/usr/local/lib/python3.4/dist-
     packages/thrift/transport/TSSLSocket.py", line 99
except socket.error, e:
                   ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

我还有一个警告,似乎很重要:

/usr/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'use_2to3'
Run Code Online (Sandbox Code Playgroud)

谷歌搜索Thrift Python 3支持似乎是矛盾的. …

python thrift python-3.x

7
推荐指数
1
解决办法
7384
查看次数

用C++创建二进制(自定义长度)字符串

我正在使用Apache Thrift RPC(Compiled to C++)机制与Apache Flume进行通信.我必须使用此平台提供的特定API.
我想发送二进制数据,但RPC函数只接受std :: string作为参数.因此,我只能发送第一次出现0x00之前的二进制数据.

u_char bin[10] = {'a','b',1,'d','e',0,'2','3','4','5'};
// Takes only the first 5 bytes, and sets a length of 5
string art_test((const char *)bin);
Run Code Online (Sandbox Code Playgroud)

我搜索了源代码,我调用的函数将str.data()转换为(uint8_t*)并发送长度为str.size()的数据.

uint32_t ssize = static_cast<uint32_t>(str.size());
trans_->write((uint8_t*)str.data(), ssize);
Run Code Online (Sandbox Code Playgroud)

有没有办法创建一个'二进制字符串',uint8_t作为数据并具有指定的长度?甚至可能用所需的二进制数据创建我自己的字符串的内存表示.

c++ thrift thrift-protocol c++11

5
推荐指数
0
解决办法
70
查看次数

标签 统计

thrift ×2

c++ ×1

c++11 ×1

python ×1

python-3.x ×1

thrift-protocol ×1