Reputation: 1345
Is it possible to convert an UUID into a 128 bit integer using c++ under linux . Once I convert UUID to integer, I need to convert the 16 byte integer into a byte array so that I can send it to another server via TCP.
As far as I know(correct me if I am wrong), there's no out of the box support for dealing with 16 byte integers in C++, can you please shed some light on how to do this? If it's not possible to store and send it as an integer, I am thinking about sending the uuid as string.
Upvotes: 3
Views: 6161
Reputation: 88235
Why do you want to represent it as a 128 bit integer?
How is the UUID represented? Presumably it's a string or already some 16-byte type. If it's a string then you can compute the 16-byte array representation yourself, and if it's already some 16-byte long type then you can just view it directly as a 16-byte array.
As always, whatever you do you'll have to be sure all parties agree on byte ordering for the network representation.
C++ implementations aren't required to have a 128 bit integer type, but one of the built in types may be 128 bits. long long
perhaps. Or your implementation might provide an extended integer type you can use.
Clang and I think GCC both support a type __uint128_t, but unfortunately do not follow the C++ requirements for extended integers for this type. However 128 bit arithmetic should work and so you should be able to do the normal things to stick a UUID into this type and then view it as a 16-byte array.
Upvotes: 4
Reputation: 2541
For implementing 16 byte integers in C++ you can check out:
http://straymindcough.blogspot.com/2012/01/on-int128t.html
As for: "Is it possible to convert an UUID into a 128 bit integer using c++ under linux". Answer is Yes.
Kind regards,
Bo
Upvotes: 0