Created
June 21, 2017 08:07
-
-
Save ksss/902c30f04cee540ad940ce8f57c2ffbe to your computer and use it in GitHub Desktop.
uuid pack/unpack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def packuuid(uuid) | |
uuid.split('-').pack("H8H4H4H4H12") | |
end | |
def unpackuuid(byte) | |
byte.unpack("H8H4H4H4H12").join('-') | |
end | |
uuid = "43e1254f-2d13-4193-b4b4-b9520ef0e9f3" | |
p uuid.length #=> 36 | |
packed = packuuid(uuid) | |
p packed #=> "C\xE1%O-\x13A\x93\xB4\xB4\xB9R\x0E\xF0\xE9\xF3" | |
p packed.length #=> 16 | |
p unpackuuid(packed) #=> "43e1254f-2d13-4193-b4b4-b9520ef0e9f3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment