Boost uuid + boost endian
I need to place uuids at locations in memory that I don't control (a pointer is passed to me (to shm backed by file)), but I have to make sure that what I store at the given pointers will be portable, ie I would like to use boost::endian to settle on little endian for the uuids. Is it possible to combine boost::endian and boost:uuid for that?
You don't need to worry about endianness with UUIDs. They are not treated as numeric values. They are simply opaque blocks of 16 bytes. The only meaningful operation you can perform on UUIDs is comparison for equality.
The endianness of a UUID does matter (contrary to @Ferruccio). The endianness of a UUID can vary by implementation and platform. As discussed here, UUIDs are governed by RFC 4122 which only recommends that UUIDs be stored in big-endian format.
Within a particular implementation or protocol, then yes, you can just do a byte-comparison. (That is one of the benefits of UUIDs.)
For example:
So yes, to be portable you should specify what endianness you are using to store them and byte-swap as needed to be consistent.
链接地址: http://www.djcxy.com/p/91450.html上一篇: UUID真的很独特吗?