-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Python Prototype for v7 #2
Conversation
Added v7 Python prototype plus testing
Thanks for the pull. A quick glance with my morning coffee looks good. I will grab a copy this afternoon and run through some deeper reviews and some testing. Appreciate the help! |
You can modify it or refuse it if you think it is not a compliant implementation. There are some aspects of this implementation that can be problematic:
|
Ah, thanks for the heads up. |
@fabiolimace I updated v7 in branch uuidv7-python
Testing I did seems okay. Let me know what you think. (Note: I did replace your splices because I am terrible with bitwise operations). I also added f4b6a3/uuid-creator to the readme table for UUIDv6 @bradleypeabody In testing this implementation I found that we may need to update draft 01. NS only needs 30 bits for subsec and our example for NS example in 4.4.4.1. UUIDv7 Encoding used too many bits. Worth also double-checking Millisecond and Microsecond too.
It is an easy fix, we just need to give 8 bits back to the Random part of
|
@kyzer-davis Now it's much better. I also wanted to replace the bitwise operations. Thanks! I think this patch can fix the problem of bad decoding that forced the use of padding:
If you want to test the UUID time you can apply these changes to testing_v6.py
testing_v7.py
The file And thank you for the inclusion of the uuid-creator! |
I think we can avoid the timestamp padding doing 2 changes in the file Change 1: ### Binary Conversions
### Need subsec_a (12 bits), subsec_b (12-bits), and subsec_c (leftover bits starting subsec_seq_node)
(-) unixts = f'{sec:032b}'
(-) unixts = unixts + "0000" # Pad end with 4 zeros to get 36-bit
subsec_binary = f'{subsec:030b}' ### Binary Conversions
### Need subsec_a (12 bits), subsec_b (12-bits), and subsec_c (leftover bits starting subsec_seq_node)
(+) nixts = f'{sec:036b}'
subsec_binary = f'{subsec:030b}' Change 2: # Convert Hex to Int then splice in dashes
(-) UUIDv7_hex = hex(int(UUIDv7_bin, 2))[2:]
UUIDv7_formatted = '-'.join( # Convert Hex to Int then splice in dashes
(+) UUIDv7_hex = f'{UUIDv7_int:032x}' # int to hex
UUIDv7_formatted = '-'.join( After tthese changes the UUID is generated with the right length (36) without padding:
The padding can result in different time when one tries to call |
|
Added v7 Python prototype plus testing