version8.rst 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. .. _rfc4122.version8:
  2. =================
  3. Version 8: Custom
  4. =================
  5. .. note::
  6. Version 8, custom UUIDs are a new format of UUID, proposed in an
  7. `Internet-Draft under review`_ at the IETF. While the draft is still going
  8. through the IETF process, the version 8 format is not expected to change
  9. in any way that breaks compatibility.
  10. Version 8 UUIDs allow applications to create custom UUIDs in an RFC-compatible
  11. way. The only requirement is the version and variant bits must be set according
  12. to the UUID specification. The bytes provided may contain any value according to
  13. your application's needs. Be aware, however, that other applications may not
  14. understand the semantics of the value.
  15. .. warning::
  16. The bytes should be a 16-byte octet string, an open blob of data that you
  17. may fill with 128 bits of information. However, bits 48 through 51 will be
  18. replaced with the UUID version field, and bits 64 and 65 will be replaced
  19. with the UUID variant. You must not rely on these bits for your application
  20. needs.
  21. .. code-block:: php
  22. :caption: Generate a version 8, custom UUID
  23. :name: rfc4122.version8.example
  24. use Ramsey\Uuid\Uuid;
  25. $uuid = Uuid::uuid8("\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff");
  26. printf(
  27. "UUID: %s\nVersion: %d\n",
  28. $uuid->toString(),
  29. $uuid->getFields()->getVersion()
  30. );
  31. This will generate a version 8 UUID and print out its string representation.
  32. It will look something like this:
  33. .. code-block:: text
  34. UUID: 00112233-4455-8677-8899-aabbccddeeff
  35. Version: 8
  36. .. _Internet-Draft under review: https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis-00#section-5.8