Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Uuidv7 NULL character
Forum Updated to NodeBB v4.3 + New Features

Uuidv7 NULL character

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 131 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • piervalliP Offline
    piervalliP Offline
    piervalli
    wrote last edited by
    #1

    Hello

    on Android this method ha created a uuid v7 with NULL values, Claude he advised me to put
    quint64 big = qToBigEndian(random);
    What you think
    Thanks?
    PS Source code is uuiv7 on versione Qt6.8

            QUuid result;
            std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> tp = std::chrono::system_clock::now();
            using namespace std::chrono;
            const nanoseconds nsecSinceEpoch = tp.time_since_epoch();
            const auto msecSinceEpoch = floor<milliseconds>(nsecSinceEpoch);
            const quint64 frac = (nsecSinceEpoch - msecSinceEpoch).count();
            // Lower 48 bits of the timestamp
            const quint64 msecs = quint64(msecSinceEpoch.count()) & 0xffffffffffff;
            result.data1 = uint(msecs >> 16);
            result.data2 = ushort(msecs);
            // rand_a: use a 12-bit sub-millisecond timestamp for additional monotonicity
            // https://datatracker.ietf.org/doc/html/rfc9562#monotonicity_counters (Method 3)
    
            // "frac" is a number between 0 and 999,999, so the lowest 20 bits
            // should be roughly random. Use the high 12 of those for additional
            // monotonicity.
            result.data3 = frac >> 8;
            result.data3 &= 0x0FFF;
            result.data3 |= ushort(7) << 12;
    
            // rand_b: 62 bits of random data (64 - 2 bits for the variant)
            const quint64 random = QRandomGenerator::system()->generate64();
            quint64 big = qToBigEndian(random);
            memcpy(result.data4, &big, sizeof(quint64));
            result.data4[0] = (result.data4[0] & 0x3F) | 0x80; // UV_DCE
            return result;
    

    f7fe12f7-7629-422a-84ec-8a985e599599-image.png

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote last edited by
      #2

      What do you think

      Not much to do with Qt here. You are using QUuid as a dumb container and QRandomGenerator to obtain a single number. Everything else is bit bashing (I have not checked its correctness).

      For a UUID v7 the 48-bits of timestamp should a big endian (i.e. data1 and data2 combined). Endianness of the 74-bit random component seems to me largely irrelevant.

      Whatever is converting your binary data to the printable string you posted is broken. If the byte that resulted in "NUL NUL" in the string is indeed zero then it should be generating "00" in the string. Since we cannot see that code we really cannot help with that.

      If you were using Qt 6.9+ then QUuid::createUuidV7() would generate a correct UUID v7 value for you.

      1 Reply Last reply
      3
      • piervalliP Offline
        piervalliP Offline
        piervalli
        wrote last edited by
        #3

        Thanks, for comments

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved