[Python-Dev] uuid module - byte order issue

Oren Tirosh oren at hishome.net
Fri Aug 4 20:26:09 CEST 2006


On 04/08/06, Ka-Ping Yee <python-dev at zesty.ca> wrote:
> On Thu, 3 Aug 2006, Oren Tirosh wrote:
> > The UUID module uses network byte order, regardless of the platform
> > byte order. On little-endian platforms like Windows the ".bytes"
> > property of UUID objects is not compatible with the memory layout
>
> RFC 4122 says:
>
>     In the absence of explicit application or presentation protocol
>     specification to the contrary, a UUID is encoded as a 128-bit
>     object, as follows:
>
>     The fields are encoded as 16 octets, with the sizes and order of
>     the fields defined above, and with each field encoded with the
>     Most Significant Byte first (known as network byte order).

RFC 4122 defines a canonical byte order for UUIDs but also makes
explicit reference to the fact that UUIDs are stored locally in native
byte order. The final step in the RFC 4122 UUID generation algorithm
is:

>   o  Convert the resulting UUID to local byte order.

So this is not another case of the
Microsoft-implements-RFC-incorrectly syndrome. After all, they are one
of the co-authors of the document.

Compatibility with Windows "GUIDs" may be one of the most important
use cases for the UUID module. It's important to resolve this or users
will have unpleasant surprises. I did.

alternatives:

1. Default is big endian byte order. Little endian is explicit.
2. Default is native byte order. Little endian and big endian are explicit.
3. No default. Little endian and big endian are both explicit.

All three are relevant for both the constructor and retrieving the
byte representation.

  Oren


More information about the Python-Dev mailing list