简体   繁体   中英

apache thrift, serialize unsigned

Currently i need to transfer data between C++ and Python applications.

As long as Thrift doesn't work with unsigned int , what's the best way to transfer 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? In C++/C++ applications i can just static_cast<signed/unsigned>(unsigned/signed) for conversion, but what about Python?

There are two options that make sense (and a bunch of others):

  1. Use the next largest signed integer with Thrift. Of course, with UINT64 this is not possible, as there is no i128, but it works up to 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

But again, I'd recommend 1. or 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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