mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-01 00:28:18 +00:00
tool: uuid128_format parses UUID128 and prints it as both big and little endian
This commit is contained in:
parent
1c7ac872de
commit
aa487f40a7
34
tool/uuid128_formats.py
Executable file
34
tool/uuid128_formats.py
Executable file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Parase and dump UUID128 in various formats
|
||||
|
||||
import codecs
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import string
|
||||
import sys
|
||||
|
||||
usage = '''
|
||||
Usage: ./uuid128_formats.py UUID128
|
||||
'''
|
||||
|
||||
def twoByteLEFor(value):
|
||||
return [ (value & 0xff), (value >> 8)]
|
||||
|
||||
def parseUUID128(uuid):
|
||||
parts = re.match("([0-9A-Fa-f]{4})([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})([0-9A-Fa-f]{4})([0-9A-Fa-f]{4})", uuid)
|
||||
uuid_bytes = []
|
||||
for i in range(8, 0, -1):
|
||||
uuid_bytes = uuid_bytes + twoByteLEFor(int(parts.group(i),16))
|
||||
return uuid_bytes
|
||||
|
||||
if (len(sys.argv) < 2):
|
||||
print(usage)
|
||||
sys.exit(1)
|
||||
|
||||
uuid128 = sys.argv[1]
|
||||
uuid_bytes = parseUUID128(uuid128)
|
||||
print('UUID128: %s' % uuid128)
|
||||
print('little endian: %s' % ', '.join( [hex(i) for i in uuid_bytes] ))
|
||||
print('big endian: %s' % ', '.join( [hex(i) for i in reversed(uuid_bytes)] ))
|
Loading…
Reference in New Issue
Block a user