Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 42 additions & 18 deletions SimpleBaseLib/src/Misc/SbpBinaryPrimitives.pas
Original file line number Diff line number Diff line change
Expand Up @@ -145,56 +145,80 @@ class procedure TBinaryPrimitives.CheckBounds(const AData: TSimpleBaseLibByteArr

class function TBinaryPrimitives.LeToNativeUInt16(AValue: UInt16): UInt16;
begin
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := AValue;
{$IFDEF FPC}
Result := LEtoN(AValue);
{$ELSE}
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := AValue;
{$ELSE}
Result := TBitOperations.ReverseBytesUInt16(AValue);
{$ENDIF}
{$ENDIF SIMPLEBASELIB_LITTLE_ENDIAN}
{$ENDIF FPC}
end;

class function TBinaryPrimitives.LeToNativeUInt32(AValue: UInt32): UInt32;
begin
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := AValue;
{$IFDEF FPC}
Result := LEtoN(AValue);
{$ELSE}
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := AValue;
{$ELSE}
Result := TBitOperations.ReverseBytesUInt32(AValue);
{$ENDIF}
{$ENDIF SIMPLEBASELIB_LITTLE_ENDIAN}
{$ENDIF FPC}
end;

class function TBinaryPrimitives.LeToNativeUInt64(AValue: UInt64): UInt64;
begin
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := AValue;
{$IFDEF FPC}
Result := LEtoN(AValue);
{$ELSE}
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := AValue;
{$ELSE}
Result := TBitOperations.ReverseBytesUInt64(AValue);
{$ENDIF}
{$ENDIF SIMPLEBASELIB_LITTLE_ENDIAN}
{$ENDIF FPC}
end;

class function TBinaryPrimitives.BeToNativeUInt16(AValue: UInt16): UInt16;
begin
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := TBitOperations.ReverseBytesUInt16(AValue);
{$IFDEF FPC}
Result := BEtoN(AValue);
{$ELSE}
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := TBitOperations.ReverseBytesUInt16(AValue);
{$ELSE}
Result := AValue;
{$ENDIF}
{$ENDIF SIMPLEBASELIB_LITTLE_ENDIAN}
{$ENDIF FPC}
end;

class function TBinaryPrimitives.BeToNativeUInt32(AValue: UInt32): UInt32;
begin
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := TBitOperations.ReverseBytesUInt32(AValue);
{$IFDEF FPC}
Result := BEtoN(AValue);
{$ELSE}
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := TBitOperations.ReverseBytesUInt32(AValue);
{$ELSE}
Result := AValue;
{$ENDIF}
{$ENDIF SIMPLEBASELIB_LITTLE_ENDIAN}
{$ENDIF FPC}
end;

class function TBinaryPrimitives.BeToNativeUInt64(AValue: UInt64): UInt64;
begin
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := TBitOperations.ReverseBytesUInt64(AValue);
{$IFDEF FPC}
Result := BEtoN(AValue);
{$ELSE}
{$IFDEF SIMPLEBASELIB_LITTLE_ENDIAN}
Result := TBitOperations.ReverseBytesUInt64(AValue);
{$ELSE}
Result := AValue;
{$ENDIF}
{$ENDIF SIMPLEBASELIB_LITTLE_ENDIAN}
{$ENDIF FPC}
end;

// ============================================================================
Expand Down
Loading