{$mode objfpc}{$H+}
{$Define FPC_REQUIRES_PROPER_ALIGNMENT}{for testing}
type
TSessionID = array [0..31] of Byte;
PSessionID = ^TSessionID;
function ToHex(constref SID: TSessionID): String;
{$IfDef FPC_REQUIRES_PROPER_ALIGNMENT}
type
T2Chars = array [0..1] of Char;
P2Chars = ^T2Chars;
var
i: SizeUInt;
{$EndIf}
begin
{$IfDef FPC_REQUIRES_PROPER_ALIGNMENT}
if (PtrUInt(@SID[0]) and 7) = 0 then
Result:=
HexStr(NtoBE(PQWord(@SID[0])^), 16) +
HexStr(NtoBE(PQWord(@SID[8])^), 16) +
HexStr(NtoBE(PQWord(@SID[16])^), 16) +
HexStr(NtoBE(PQWord(@SID[24])^), 16)
else begin
SetLength(Result, Length(SID) * 2);
for i:= 0 to High(SID) do
P2Chars(@Result[i * 2 + 1])^:= HexStr(SID[i], 2);
end;
{$Else}
Result:=
HexStr(NtoBE(PQWord(@SID[0])^), 16) +
HexStr(NtoBE(PQWord(@SID[8])^), 16) +
HexStr(NtoBE(PQWord(@SID[16])^), 16) +
HexStr(NtoBE(PQWord(@SID[24])^), 16);
{$EndIf}
end;
var
SID: TSessionID = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31);
p: PByte;
begin
p:= GetMem(SizeOf(TSessionID) + 1);
Move(SID, PByte(p + 1)^, SizeOf(TSessionID));
Writeln(ToHex(SID), LineEnding, ToHex(PSessionID(p + 1)^));
end.