Subject Re: UUID (octets) to something readable
Author woodsmailbox
I've solved it with this little piece of fpc code below -- tested only
on linux -- (dunno how to post files so just copy/paste this thing):

{$LONGSTRINGS ON}
{$MODE DELPHI}

library fpc_udfs;

uses
classes,
sysutils;

// either malloc work in linux. pick the first for portability, pick
the second for not depending on ib_util.
// function malloc(size: Longint): Pointer; cdecl; external 'ib_util'
name 'ib_util_malloc';
function malloc(size: Longint): Pointer; cdecl; external 'libc';
procedure free(p: Pointer); cdecl; external 'libc';

// declare ... varchar(N) charset octets null returns cstring(N*2)
charset <any-sbc-or-utf8> free_it ...
function bin_to_hex(token: PChar): PChar; cdecl; export;
var
len: Longint;
begin
result := nil;
if (token = nil) then
exit;

len := PWord(token)^;
result := malloc(len*2 + 1);
BinToHex(@token[2], result, len);
result[len*2] := #0;
end;

// declare ... cstring(N) charset <any-sbc> null returns varchar(N/2)
charset octets free_it
function hex_to_bin(token: PChar): PChar;
var
len: Longint;
begin
result := nil;
if (token = nil) then
exit;

len := strlen(token);
if (len mod 2 <> 0) then
exit;

result := malloc(2 + len div 2);
PWord(result)^ := HexToBin(token, @result[2], len div 2);
end;

exports
bin_to_hex,
hex_to_bin;

begin
IsMultiThread := True; // this is controversial for me (crashes
with undocumented RTE 244 if loaded in normal programs!!)


end.



DECLARE EXTERNAL FUNCTION BIN_TO_HEX
VARCHAR(2048) CHARACTER SET OCTETS NULL
RETURNS CSTRING(4096) CHARACTER SET ASCII FREE_IT
ENTRY_POINT 'bin_to_hex' MODULE_NAME '/lib/fpc_udfs.so';


DECLARE EXTERNAL FUNCTION HEX_TO_BIN
CSTRING(4096) CHARACTER SET ASCII NULL
RETURNS VARCHAR(2048) CHARACTER SET OCTETS FREE_IT
ENTRY_POINT 'hex_to_bin' MODULE_NAME '/lib/fpc_udfs.so';