简体   繁体   English

apache节俭,序列化未签名

[英]apache thrift, serialize unsigned

Currently i need to transfer data between C++ and Python applications. 目前,我需要在C ++和Python应用程序之间传输数据。

As long as Thrift doesn't work with unsigned int , what's the best way to transfer unsigned ? 只要Thrift不能与unsigned int ,传输unsigned的最佳方法是什么?

Is there only way like: 是否只有这样的方式:

  1. assign unsigned to signed 将未签名分配给已签名
  2. serialize -> send -> receive -> deserialize this signed 序列化->发送->接收->反序列化此签名
  3. assign signed to unsigned 将已签名分配给未签名

Should i do it manually all the time or there are already some 3rd party libraries? 我应该一直手动进行还是应该有一些第三方库?

How do i do it in the case of C++/Python applications? 在C ++ / Python应用程序中该怎么办? In C++/C++ applications i can just static_cast<signed/unsigned>(unsigned/signed) for conversion, but what about Python? 在C ++ / C ++应用程序中,我只能进行static_cast<signed/unsigned>(unsigned/signed)转换,但是Python呢?

There are two options that make sense (and a bunch of others): 有两个有意义的选择(以及其他许多选择):

  1. Use the next largest signed integer with Thrift. Thrift使用下一个最大的有符号整数。 Of course, with UINT64 this is not possible, as there is no i128, but it works up to UINT32 当然,由于没有i128,因此无法使用UINT64,但是它可以在UINT32上使用
  2. Cast the unsigned bits into signed. 将无符号位转换为有符号。 Not very clean and requires documentation, but it works. 不是很干净,需要文档,但可以。

The "bunch of others" include “其他人”包括

  • Convert it into a string and back. 将其转换为字符串并返回。 And watch your performance going down. 并观察您的性能下降。
  • Use binary type. 使用二进制类型。 Ok, that's a bit far out, but still possible and can be done by just reinterpreting the bits as with 2. above 好的,这有点遥远,但仍然可行,可以通过重新解释上述2中的位来完成。

But again, I'd recommend 1. or 2. 但是我还是建议1.或2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM