我有一个类作为参数(二进制文件内容).
我想将python'str'类型转换为unsigned char的向量,但仅用于我的一个类方法.
BOOST_PYTHON_MODULE(hello) { class_<Hello>("Hello").
// This method takes a string as parameter and print it
.def("printChar", &Hello::printChar)
// This method takes a vector<unsigned char> parameter
.def("storeFile", &Hello::storeFile) }
Run Code Online (Sandbox Code Playgroud)
使用自定义转换器似乎是我需要的但是如果我修改我的boost :: python :: converter :: registry它将修改我对printChar的所有调用以及所有传递string的python方法将参数转换为vector.
如何注册每个方法的转换器?
我在使用ctypes绑定时遇到问题,并且ctypes文档使我的头部有点受伤。
我有一个远程网络客户端正在发送二进制数据,而我正在使用的库(Mosquitto,用于MQTT消息代理)提供了一种ctypes方法,用于从网络获取原始二进制数据。这是“ LP_c_ubyte”类型。有什么有效的方法可以将其转换回python'str'对象?
我需要一组常规字节来用于M2Crypto的解密功能。
pp = ''.join(chr(msg.payload[i]) for i in xrange(msg.payloadlen))
clear_text = rsa.private_decrypt(pp, M2Crypto.RSA.pkcs1_padding)
Run Code Online (Sandbox Code Playgroud)
这有效,但是非常难看。
我可以将客户端更改为首先对所有内容进行base64编码,然后在此端取消对unbase64的编码,但这似乎也可以解决。
有没有更好的方法?