UuidFromBytes$ ( bank[,offset][,layout] )
Parameters
|
bank - source Bank with at least 16 bytes at offset offset (optional) - byte position to read from; 0 (default) layout (optional) - byte order to read: UUID_BYTES_RFC: RFC network/display order (default) UUID_BYTES_WINDOWS: mixed-endian Windows GUID / .NET Guid.ToByteArray() order |
Description
|
Reads 16 raw bytes from a Bank and returns canonical UUID text. The decode half of binary UUID storage: a binary save file or network packet delivers an id as 16 bytes, and UuidFromBytes turns them back into the lowercase dashed text your game compares and stores - the same canonical form CreateUuid and NormalizeUuid produce. UuidToBytes is the exact inverse. The layout must match whoever wrote the bytes. UUID_BYTES_RFC reads them in display order; UUID_BYTES_WINDOWS reads the mixed-endian Windows GUID / .NET Guid.ToByteArray() layout, where the first three groups are little-endian. Reading with the wrong layout does not fail - it returns a perfectly formed but WRONG id, the kind of bug that only surfaces when saves stop matching. Round trips work only when both directions agree, so state the layout wherever the format is documented. Any 16 bytes convert - the command formats whatever it reads and does not police version bits, so garbage bytes become a syntactically valid id. It returns exactly what is stored; validate provenance at a higher level. A Bank range without 16 bytes at the offset, or an unknown layout constant, is a programming error. For the full rules, see the Application Data language reference. Requires Extended mode. See also: UuidToBytes, CreateUuid, UuidValid, NormalizeUuid, CreateBank. |
Example
; UuidFromBytes Example ; --------------------- ; Requires Extended mode. ; A binary save file delivered an object id as 16 raw bytes bank=CreateBank(16) For i=0 To 15 PokeByte bank,i,i*17 ; Bytes 00,11,22,...,ff Next hex_text$="" For i=0 To 15 hex_text=hex_text+Right(Hex(PeekByte(bank,i)),2) Next Print "Raw bytes in the bank: "+Lower(hex_text) Print "" ; UuidFromBytes reads exactly 16 bytes and returns canonical text. ; UUID_BYTES_RFC treats them as network/display order... Print "Read as RFC layout:" Print " "+UuidFromBytes(bank,0,UUID_BYTES_RFC) Print "" ; ...while UUID_BYTES_WINDOWS treats the first three groups as ; little-endian (Windows GUID / .NET Guid.ToByteArray() layout) Print "Read as Windows layout:" Print " "+UuidFromBytes(bank,0,UUID_BYTES_WINDOWS) Print "" Print "Same bytes, different text - always agree on a layout!" FreeBank bank Print "" Print "Press any key to close the example" WaitKey End
Index