Unit rtcSystem

Description
Uses
Classes, Interfaces, Objects and Records
Functions and Procedures
Types
Constants
Variables

Description

System utilities - Copyright 2004-2018 (c) Teppi Technology (https://rtc.teppi.net)

Global System Parameters, Classes and Functions: Unicode<->ANSI support, File & Folder Access, Tick Timer, Critical Sections, Array & String manipulation.

Overview

Classes, Interfaces, Objects and Records

Name Description
Class ERtcSystem  
Class ERtcSocketError  
Class ERtcFatalSockException  
Class TRtcFileStream RTC File Stream implementation
Class TRtcByteArrayStream RTC Byte Array Stream implementation
Class TRtcPersistent RTC "TPersistent" class
Class TRtcTimeoutsOfAPI  
Class TRtcEvent  
Class TRtcCritSec  
Class TRtcRWSec  
Class TRtcHugeString Fast Huge Ansi String manipulation
Class TRtcHugeByteArray Fast Huge Byte Array manipulation
Class tRtcFastStrObjList Fast Ansi String Object List
Class tRtcFastStringObjList Fast Unicode / Wide String Object List
Class tRtcFastStrValueList Fast Name = Value String List
Class tRtcDynamicHeaderTable Dynamic Header Table

Functions and Procedures

procedure RtcSetAnsiCodePage(page:RtcAnsiCodePages);
function RtcUnicodeToAnsiString(const Source:RtcString):RtcString;
function RtcAnsiToUnicodeString(const Source:RtcString):RtcString;
function Get_TickTime:Cardinal;
function GetTickTime:Cardinal;
function GetTickTime64:int64;
function GetMyThreadID:RtcThrID;
function File_Exists(const fname:RtcWideString):boolean;
function File_Size(const fname:RtcWideString):int64;
function Read_File(const fname:RtcWideString; Loc,Size:int64; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):RtcString; overload;
function Read_File(const fname:RtcWideString; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):RtcString; overload;
function Read_FileEx(const fname:RtcWideString; Loc,Size:int64; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):RtcByteArray; overload;
function Read_FileEx(const fname:RtcWideString; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):RtcByteArray; overload;
function Scan_File(const fname:RtcWideString; const search_string:RtcByteArray; BufferSize:integer; Loc,Size:int64; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):int64; overload;
function Delete_File(const fname:RtcWideString):boolean;
function Rename_File(const old_name,new_name:RtcWideString):boolean;
function Write_File(const fname:RtcWideString; const Data:RtcString; Loc:int64; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone; Retries:integer=-1; RetryDelayMS:integer=-1):boolean; overload;
function Write_File(const fname:RtcWideString; const Data:RtcString; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone; Retries:integer=-1; RetryDelayMS:integer=-1):boolean; overload;
function Write_FileEx(const fname:RtcWideString; const Data:RtcByteArray; Loc:int64; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone; Retries:integer=-1; RetryDelayMS:integer=-1):boolean; overload;
function Write_FileEx(const fname:RtcWideString; const Data:RtcByteArray; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone; Retries:integer=-1; RetryDelayMS:integer=-1):boolean; overload;
function Copy_FileEx(const fromName,toName:RtcWideString; fromLoc,toLoc,fromSize,maxSize:int64; fromAccessMode:TRtcFileAccessMode=rtc_ShareDenyNone; toAccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):boolean;
function Open_File(const fname:RtcWideString; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):TRtcFileHdl;
function Read_File(const f:TRtcFileHdl; Loc,Size:int64):RtcString; overload;
function Scan_File(const f:TRtcFileHdl; const search_string:RtcByteArray; BufferSize:integer; Loc,Size:int64):int64; overload;
procedure Close_File(const f:TRtcFileHdl);
function File_Age(const fname:RtcWideString):TDateTime;
function GetTempDirectory:RtcWideString;
function GetTempFile:RtcWideString;
procedure AddBytes(var Dest:RtcByteArray; Plus:Byte); overload;
procedure AddBytes(var Dest:RtcByteArray; const Plus:RtcByteArray); overload;
procedure AddBytes(var Dest:RtcByteArray; const Plus:RtcByteArray; loc:Integer; len:Integer=-1); overload;
procedure DelBytes(var Dest:RTcByteArray; Len:Integer);
function isRtcStringOK(const Source:RtcString):boolean;
procedure RtcStringCheck(const Source:RtcString);
function RtcBytesZeroToString(const Source:RtcByteArray):RtcString; overload;
function RtcStringToBytesZero(const Source:RtcString):RtcByteArray; overload;
function RtcBytesZeroToString(const Source:RtcByteArray; loc:Integer; len:Integer=-1):RtcString; overload;
function RtcStringToBytesZero(const Source:RtcString; loc:Integer; len:Integer=-1):RtcByteArray; overload;
function RtcBytesToString(const Source:RtcByteArray):RtcString; overload;
function RtcStringToBytes(const Source:RtcString):RtcByteArray; overload;
function RtcBytesToHex(const Source:RtcByteArray):RtcString; overload;
function RtcBytesToHex(const Source:RtcByteArray; Separate:Byte; const Separator:RtcString):RtcString; overload;
function RtcBytesToString(const Source:RtcByteArray; loc:Integer; len:Integer=-1):RtcString; overload;
function RtcStringToBytes(const Source:RtcString; loc:Integer; len:Integer=-1):RtcByteArray; overload;
function RtcPBytesZeroToString(var Source):RtcString;
function RtcPBytesToString(var Source; Len:Cardinal):RtcString; overload;
procedure RtcStringToPBytes(Source:RtcString; var Dest; Len:Cardinal); overload;
procedure RtcStringToPBytes(Source:RtcString; var Dest; Loc, Len:Cardinal); overload;
procedure RtcStringToPBytesZero(Source:RtcString; var Dest; Loc, Len:Cardinal); overload;
function RtcBytesToWideString(const Source:RtcByteArray; loc:Integer=0; len:Integer=-1):RtcWideString;
function RtcWideStringToBytes(const Source:RtcWideString; loc:Integer=1; len:Integer=-1):RtcByteArray;
function URL_Encode(const AStr:RtcString; Safe:boolean=False):RtcString;
function URL_Decode(const AStr:RtcString; Strict:boolean=False):RtcString;
function Mime_Encode(const s: RtcString; toJSON:boolean=False): RtcString;
function Mime_Decode(const s: RtcString): RtcString;
function Mime_EncodeEx(const s: RtcByteArray; toJSON:boolean=False): RtcByteArray;
function Mime_DecodeEx(const s: RtcByteArray): RtcByteArray; overload;
function Mime_DecodeEx(const s: RtcString): RtcByteArray; overload;
function Utf8Encode(const Source: RtcWideString; SourceOffset:Integer=1; SourceLength:Integer=-1): RtcString;
function Utf8Decode(const Source: RtcString; SourceOffset:Integer=1; SourceLength:Integer=-1):RtcWideString;
function Utf8EncodeEx(const Source: RtcWideString; SourceOffset:Integer=1; SourceLength:Integer=-1): RtcByteArray;
function Utf8DecodeEx(const Source: RtcByteArray; SourceOffset:Integer=0; SourceLength:Integer=-1):RtcWideString;
function Huff_CheckLength(const Source:RtcString):Integer;
function Huff_EncodeEx(const Source:RtcString):RtcByteArray;
function Huff_Encode(const Source:RtcString):RtcString;
function Huff_DecodeEx(const Data:RtcByteArray; From:Integer=0; Len:Integer=-1):RtcString;
function Huff_Decode(const Data:RtcString):RtcString;
function LInt_EncodeEx(const Value:int64; PrefixBits:Byte=8):RtcByteArray;
function LInt_DecodeEx(const Data:RtcByteArray; var Len:Byte; PrefixBits:Byte=8; FromByte:Integer=0):int64;
function LWord_DecodeEx(const Data:RtcByteArray; var Len:Byte; PrefixBits:Byte=8; FromByte:Integer=0):Cardinal;
function LWord_EncodeEx(const Value:Cardinal; PrefixBits:Byte=8):RtcByteArray;
function PosWEx(const c,s:RtcWideString):integer; overload;
function PosWEx(const c,s:RtcWideString; at:integer):integer; overload;
function PosEx(const c,s:RtcString):integer; overload;
function PosEx(const c,s:RtcString; at:integer):integer; overload;
function PosEx(const c:RtcString; const s:RtcByteArray):integer; overload;
function PosEx(const c:RtcString; const s:RtcByteArray; at:integer):integer; overload;
function PosEx(const c:RtcChar; const s:RtcString):integer; overload;
function PosEx(const c:RtcChar; const s:RtcString; at:integer):integer; overload;
function PosEx(const c,s:RtcByteArray):integer; overload;
function PosEx(const c,s:RtcByteArray; at:integer):integer; overload;
function LWord2Str(i:Cardinal):RtcString;
function Int2Str(i:integer):RtcString; overload;
function Int2Str(i:int64):RtcString; overload;
function Int2Hex(i,l:integer):RtcString; overload;
function Int2WStr(i:int64):RtcWideString;
function Str2Int(const s:RtcString):integer; overload;
function Str2Int(const s:RtcWideString):integer; overload;
function Str2IntDef(const s:RtcString; def:integer):integer; overload;
function Str2LWord(const s:RtcString):Cardinal; overload;
function Str2LWordDef(const s:RtcString; def:Cardinal):Cardinal; overload;
function Str2Int64(const s:RtcString):Int64; overload;
function Str2Int64Def(const s:RtcString; def:int64):int64; overload;
function LWordTo6bit(const i: Cardinal):RtcString;
function LWordFrom6bit(const r: RtcString):Cardinal;

Types

TRtcFileHdl=THandle;
TRtcFileAccessMode = (...);
RtcWideString = rtcTypes.RtcWideString;
RtcWideChar = rtcTypes.RtcWideChar;
RtcString = rtcTypes.RtcString;
RtcChar = rtcTypes.RtcChar;
RtcByteArray = rtcTypes.RtcByteArray;
TRtcStrFixType = (...);
TRtcWaitResult = TWaitResult;
RtcUnicodeToAnsiFunc = function(Chr:Word):Byte;
RtcAnsiToUnicodeFunc = function(Chr:Byte):Word;
RtcAnsiCodePages = (...);

Constants

RTC_INVALID_FILE_HDL = INVALID_HANDLE_VALUE;
WAIT_INFINITE = Cardinal($FFFFFFFF);
wr_Signaled=wrSignaled;
wr_Timeout=wrTimeout;
wr_Abandoned=wrAbandoned;
wr_Error=wrError;

Variables

AppFileName:RtcWideString='';
SOCK_PACKET_SIZE:integer=1460;
SOCK_SEND_BUFFER_SIZE:integer=1460*44;
SOCK_READ_BUFFER_SIZE:integer=1460*44;
SOCK_MAX_SEND_SIZE:integer=1460*44;
SOCK_MAX_READ_SIZE:integer=1460*44;
SOCK_RECV_TIMEOUT:integer=1000*60*30;
SOCK_SEND_TIMEOUT:integer=1000*60*30;
SOCK_LISTEN_BACKLOG:integer=200;
RTC_WAIT_BEFORE_RECONNECT:integer=20;
RTC_WAIT_BEFORE_RESTART:integer=100;
RTC_WAITFOR_RELEASE_PROVIDER:integer=15;
RTC_WAITFOR_PROVIDER_FINISH:integer=50;
RTC_WRITE_RETRIES:integer=0;
RTC_WRITE_RETRY_DELAY:integer=100;
RTC_DEFAULT_TEMP_FOLDER:RtcWideString='';
RTC_STRING_FIXMODE:TRtcStrFixType=rtcStr_FixDown;
RTC_STRING_CHECK:boolean=False;
RTC_INVALID_CHAR:byte=63;
RtcUnicodeToAnsiChar:RtcUnicodeToAnsiFunc=nil;
RtcAnsiToUnicodeChar:RtcAnsiToUnicodeFunc=nil;

Description

Functions and Procedures

procedure RtcSetAnsiCodePage(page:RtcAnsiCodePages);

Set the code-page for implicit Unicode <-> ANSI conversions done by RTC. This will assign the "RtcUnicodeToAnsiChar" and "RtcAnsiToUnicodeChar" functions to use one of the built-in implementations for ANSI <-> Unicode character conversions. Supported built-in code-pages are cpWin874 and cpWin1250 through cpWin1258. Use "cpNone" to disable all implicit ANSI <-> Unicode conversions by RTC. For all other code-pages, you can write your own conversion functions and assign them manually to the "RtcUnicodeToAnsiChar" and "RtcAnsiToUnicodeChar" variables.

function RtcUnicodeToAnsiString(const Source:RtcString):RtcString;

Convert Unicode String to ANSI String with the RtcUnicodeToAnsiChar function

function RtcAnsiToUnicodeString(const Source:RtcString):RtcString;

Convert ANSI String to Unicode String with the RtcAnsiToUnicodeChar function

function Get_TickTime:Cardinal;

Cross-platform "GetTickCount" function

function GetTickTime:Cardinal;

Returns the number of milliseconds passsed since the Application was started (32-bit version). WARNING: Because "Cardinal" is a 32-bit integer type and this function returns the number of milliseconds (1/1000th of a second) passed since the last time this APPLICATION was start, the "GetTickTime" function should NOT be used to measure Time in Applications running longer than 49.7 days, because "GetTickTime" will overflow once every 49.7 days.

function GetTickTime64:int64;

Returns the number of milliseconds passed since the Application was started (64-bit version). If there are no TRtcTimer instances active, then this function should be called at least once every 49.7 days for the integrated "GetTickCount" overflow hanling to work correctly. "GetTickTime64" is used internally by RTC Timers and Timeouts to trigger timed events.

function GetMyThreadID:RtcThrID;

Return ID of the current Thread (GetCurrentThreadID)

function File_Exists(const fname:RtcWideString):boolean;

Does file with name "fname" exist?

function File_Size(const fname:RtcWideString):int64;

Size of the file with name "fname"

function Read_File(const fname:RtcWideString; Loc,Size:int64; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):RtcString; overload;

Read "Size" bytes of file "fname", starting at "Loc" (0=begining), using "AccessMode" (default = rtc_ShareDenyNone)

function Read_File(const fname:RtcWideString; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):RtcString; overload;

Read complete file "fname", using "AccessMode" (default = rtc_ShareDenyNone)

function Read_FileEx(const fname:RtcWideString; Loc,Size:int64; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):RtcByteArray; overload;

Read "Size" bytes of file "fname", starting at "Loc" (0=begining), using "AccessMode" (default = rtc_ShareDenyNone)

function Read_FileEx(const fname:RtcWideString; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):RtcByteArray; overload;

Read complete file "fname", using "AccessMode" (default = rtc_ShareDenyNone)

function Scan_File(const fname:RtcWideString; const search_string:RtcByteArray; BufferSize:integer; Loc,Size:int64; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):int64; overload;

Scan up to "Size" bytes of file "fname" for RtcByteArray "search_string", starting at "Loc" (0=beginning), using "AccessMode" (default = rtc_ShareDenyNone) and up to "BufferSize" memory for scanning the file. Larger buffer size will increase scanning speed, but use more memory. Recommended are "BufferSize" values of 16000 or more bytes.

If "search_string" is found, its location in file is returned (0=beginning). If "search_string" is not found, this function returns -1.

function Delete_File(const fname:RtcWideString):boolean;

Delete file "fname"

function Rename_File(const old_name,new_name:RtcWideString):boolean;

Rename file "old_name" to "new_name"

function Write_File(const fname:RtcWideString; const Data:RtcString; Loc:int64; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone; Retries:integer=-1; RetryDelayMS:integer=-1):boolean; overload;

Write "Data" to file "fname" starting at "Loc" (0=begining, -1 = end), using "AccessMode" (default = rtc_ShareDenyNone). If write fails, retry up to "Retries" number of times (-1 = RTC_WRITE_RETRIES) with a delay of "RetryDelayMS" milliseconds (-1 = RTC_WRITE_RETRY_DELAY) between reach retry attempt.

function Write_File(const fname:RtcWideString; const Data:RtcString; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone; Retries:integer=-1; RetryDelayMS:integer=-1):boolean; overload;

Write "Data" to file "fname", overwriting old file, using "AccessMode" (default = rtc_ShareDenyNone) If write fails, retry up to "Retries" number of times (-1 = RTC_WRITE_RETRIES) with a delay of "RetryDelayMS" milliseconds (-1 = RTC_WRITE_RETRY_DELAY) between reach retry attempt.

function Write_FileEx(const fname:RtcWideString; const Data:RtcByteArray; Loc:int64; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone; Retries:integer=-1; RetryDelayMS:integer=-1):boolean; overload;

Write "Data" to file "fname" starting at "Loc" (0=begining, -1 = end), using "AccessMode" (default = rtc_ShareDenyNone) If write fails, retry up to "Retries" number of times (-1 = RTC_WRITE_RETRIES) with a delay of "RetryDelayMS" milliseconds (-1 = RTC_WRITE_RETRY_DELAY) between reach retry attempt.

function Write_FileEx(const fname:RtcWideString; const Data:RtcByteArray; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone; Retries:integer=-1; RetryDelayMS:integer=-1):boolean; overload;

Write "Data" to file "fname", overwriting old file, using "AccessMode" (default = rtc_ShareDenyNone) If write fails, retry up to "Retries" number of times (-1 = RTC_WRITE_RETRIES) with a delay of "RetryDelayMS" milliseconds (-1 = RTC_WRITE_RETRY_DELAY) between reach retry attempt.

function Copy_FileEx(const fromName,toName:RtcWideString; fromLoc,toLoc,fromSize,maxSize:int64; fromAccessMode:TRtcFileAccessMode=rtc_ShareDenyNone; toAccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):boolean;

Copy content from file "fromName" to file "toName", starting to read at "fromLoc" in "fromFile" and writing to "toLoc" in "toFile", copying "fromSize" bytes from the file "fromName" to file "toName" by using a memory buffer of "maxSize" bytes.

function Open_File(const fname:RtcWideString; AccessMode:TRtcFileAccessMode=rtc_ShareDenyNone):TRtcFileHdl;
 
function Read_File(const f:TRtcFileHdl; Loc,Size:int64):RtcString; overload;
 
function Scan_File(const f:TRtcFileHdl; const search_string:RtcByteArray; BufferSize:integer; Loc,Size:int64):int64; overload;
 
procedure Close_File(const f:TRtcFileHdl);
 
function File_Age(const fname:RtcWideString):TDateTime;

File date and time

function GetTempDirectory:RtcWideString;

Get Temporary Directory path

function GetTempFile:RtcWideString;

Get a Temporary File Name inside a Temporary Directory. (A) If "RTC_DEFAULT_TEMP_FOLDER" variable is empty (default), this function will be using the "GetTempDirectory" function to select a Temporary Folder, then use the "GetTempFileName" API (OS-specific) function to get a Temporary File Name inside that folder. (B) If "RTC_DEFAULT_TEMP_FOLDER" variable is assigned (not empty), a GUID will be used to generate a unique file name inside the folder specified by the "RTC_DEFAULT_TEMP_FOLDER" global variable.

procedure AddBytes(var Dest:RtcByteArray; Plus:Byte); overload;

Append "Plus" byte to the "Dest" byte array

procedure AddBytes(var Dest:RtcByteArray; const Plus:RtcByteArray); overload;

Append "Plus" byte array to the "Dest" byte array

procedure AddBytes(var Dest:RtcByteArray; const Plus:RtcByteArray; loc:Integer; len:Integer=-1); overload;

Append "len" items (default=all) from the "Plus" byte array to the "Dest" byte array, starting from "loc" index in the "Plus" byte array (0-based; default=0)

procedure DelBytes(var Dest:RTcByteArray; Len:Integer);

Delete "len" items from the beginning of the "Dest" byte array

function isRtcStringOK(const Source:RtcString):boolean;

Returns TRUE if "Source" can safely be used with RtcStringTo* functions (no data loss?)

procedure RtcStringCheck(const Source:RtcString);

If "Source" contains Unicode characters and "RTC_STRING_CHECK" = TRUE, raise an Exception

function RtcBytesZeroToString(const Source:RtcByteArray):RtcString; overload;

Return a "byte" String containing a zero-terminated "Source" byte array

function RtcStringToBytesZero(const Source:RtcString):RtcByteArray; overload;

Return a zero-terminated Byte array containing the "Source" string

function RtcBytesZeroToString(const Source:RtcByteArray; loc:Integer; len:Integer=-1):RtcString; overload;

Return a "byte" String containing "len" bytes from a zero-terminated "Source" byte array, starting from "loc" index (0-based)

function RtcStringToBytesZero(const Source:RtcString; loc:Integer; len:Integer=-1):RtcByteArray; overload;

Return a zero-terminated Byte array containing "len" characters from the "Source" string, starting from "loc" index (1-based)

function RtcBytesToString(const Source:RtcByteArray):RtcString; overload;

Return a String containing the "Source" byte array

function RtcStringToBytes(const Source:RtcString):RtcByteArray; overload;

Return a byte array containing the "Source" string

function RtcBytesToHex(const Source:RtcByteArray):RtcString; overload;

Return a Hexadecimal String containing the "Source" byte array

function RtcBytesToHex(const Source:RtcByteArray; Separate:Byte; const Separator:RtcString):RtcString; overload;

Return a Hexadecimal String containing the "Source" byte array, separating every "Separate" bytes using the "Separator" String.

function RtcBytesToString(const Source:RtcByteArray; loc:Integer; len:Integer=-1):RtcString; overload;

Return a String containing "len" bytes from the "Source" byte array, starting from "loc" index (0-based)

function RtcStringToBytes(const Source:RtcString; loc:Integer; len:Integer=-1):RtcByteArray; overload;

Return a byte array containing "len" characters from the "Source" string, starting from "loc" index (1-based)

function RtcPBytesZeroToString(var Source):RtcString;

Return a "byte" String from a zero-terminated "Source"

function RtcPBytesToString(var Source; Len:Cardinal):RtcString; overload;

Return "Len" characters from "Source" byte array

procedure RtcStringToPBytes(Source:RtcString; var Dest; Len:Cardinal); overload;

Copy "Len" characters from "Source" to "Dest" byte array

procedure RtcStringToPBytes(Source:RtcString; var Dest; Loc, Len:Cardinal); overload;

Copy "Len" characters starting from "Loc" index in "Source", to "Dest" byte array

procedure RtcStringToPBytesZero(Source:RtcString; var Dest; Loc, Len:Cardinal); overload;

Copy "Len" characters starting from "Loc" index in "Source", to "Dest" byte array and add #0 at the end

function RtcBytesToWideString(const Source:RtcByteArray; loc:Integer=0; len:Integer=-1):RtcWideString;

Return a WideString containing "len" characters from the "Source" byte array starting from "loc" index

function RtcWideStringToBytes(const Source:RtcWideString; loc:Integer=1; len:Integer=-1):RtcByteArray;

Return a byte array containing "len" bytes from the "Source" WideString starting from "loc" index

function URL_Encode(const AStr:RtcString; Safe:boolean=False):RtcString;

If Safe=TRUE, the following characters will NOT be encoded: Ampersand ("&") Semi-colon (";") Equals ("=") Question mark ("?") Slash ("/")

function URL_Decode(const AStr:RtcString; Strict:boolean=False):RtcString;

If Strict=TRUE, any errors in AStr (malformed string) will raise an exception. If Strict=FALSE, errors in AStr will be ignored, so that string part which can be properly decoded will be decoded, the rest will remain untouched.

function Mime_Encode(const s: RtcString; toJSON:boolean=False): RtcString;

Encode a binary String to Mime (Base-64). When called with "toJSON=True", line breaks are NOT inserted

function Mime_Decode(const s: RtcString): RtcString;

decode a Mime (Base-64) String to a binary String

function Mime_EncodeEx(const s: RtcByteArray; toJSON:boolean=False): RtcByteArray;

Encode a binary String to Mime (Base-64). When called with "toJSON=True", line breaks are NOT inserted

function Mime_DecodeEx(const s: RtcByteArray): RtcByteArray; overload;

decode a Mime (Base-64) String to a Byte Array

function Mime_DecodeEx(const s: RtcString): RtcByteArray; overload;

decode a Mime (Base-64) String to a Byte Array

function Utf8Encode(const Source: RtcWideString; SourceOffset:Integer=1; SourceLength:Integer=-1): RtcString;

Convert RtcWideString to a normal UTF-8 encoded String

function Utf8Decode(const Source: RtcString; SourceOffset:Integer=1; SourceLength:Integer=-1):RtcWideString;

Convert a normal UTF-8 encoded String to a RtcWideString

function Utf8EncodeEx(const Source: RtcWideString; SourceOffset:Integer=1; SourceLength:Integer=-1): RtcByteArray;

Convert RtcWideString to an UTF-8 encoded byte array

function Utf8DecodeEx(const Source: RtcByteArray; SourceOffset:Integer=0; SourceLength:Integer=-1):RtcWideString;

Convert an UTF-8 encoded byte array to a RtcWideString

function Huff_CheckLength(const Source:RtcString):Integer;

Returns the expected Length (in bytes) of encoded "Source" (String of 8-bit characters), when used with Huffman Code from RFC 7541 (HPACK: Header Compression for HTTP/2).
Also check related functions "Huff_Encode", "Huff_Decode", "Huff_EncodeEx" and "Huff_DecodeEx".

function Huff_EncodeEx(const Source:RtcString):RtcByteArray;

Encode "Source" using Huffman Code from RFC 7541 (HPACK: Header Compression for HTTP/2).
"Huff_CheckLength" can be used to quickly check the expected length of Encoded Source. "Huff_DecodeEx" can be used to Decode the result produced by this function.
This function is optimized for performance with minimal memory usage and produces the best results when used on short literals (down to 67% of the original size when encoded), but is NOT suitable for encoding binary data (up to 400% of the original size after encoding) and should NOT be used with Unicode text, because only 8 bits of each character are encoded.

function Huff_Encode(const Source:RtcString):RtcString;

Alias for: RtcStringToBytes(Huff_EncodeEx(Source))

function Huff_DecodeEx(const Data:RtcByteArray; From:Integer=0; Len:Integer=-1):RtcString;

Decode "Data" encoded with Huffman Code from RFC 7541 (HPACK: Header Compression for HTTP/2).
"From" (optional) defines the index in the "Data" array (0-based) where decoding should start [default=0], "Len" (optional) defines the number of bytes from "Data" to decode [default=Length(Data)-From].
Also check related functions: "Huff_CheckLength" and "Huff_EncodeEx".

function Huff_Decode(const Data:RtcString):RtcString;

Alias for: Huff_DecodeEx(RtcStringToBytes(Data))

function LInt_EncodeEx(const Value:int64; PrefixBits:Byte=8):RtcByteArray;

Encode "Value" (unsigned 64-bit integer) into a dynamic-length array of bytes, using the least number of bytes. Use the Integer Representation as described in RFC 7541, Section 5.1 (HPACK: Header Compression for HTTP/2).
"PrefixBits" is the number of bits (default=8) usable in the Prefix (1st byte in the output array). To decode the array produced by this function, you can use the "LInt_EncodeEx" function.

function LInt_DecodeEx(const Data:RtcByteArray; var Len:Byte; PrefixBits:Byte=8; FromByte:Integer=0):int64;

Decode an unsigned 64-bit Integer Value from "Data" (dynamic-length array of bytes), previously encoded using the Integer Representation as described in RFC 7541, Section 5.1 (HPACK: Header Compression for HTTP/2).
"FromByte" is the starting index (0-based, default=0) in the "Data" byte array, where decoding should begin. "PrefixBits" is the number of bits (default=8) to be decoded from the "Prefix" (1st byte in "Data"). If there was an error decoding the "Data" byte array, returns 0 and sets "Len" to 0. Otherwise, Returns the (decoded) Integer value and sets "Len" to the number bytes read from "Data".
See the "LInt_EncodeEx" function for info about encoding (reverse procedure).

function LWord_DecodeEx(const Data:RtcByteArray; var Len:Byte; PrefixBits:Byte=8; FromByte:Integer=0):Cardinal;

This function does the same as the "LInt_DecodeEx" function, but expects an unsigned 32-bit integer (Cardinal) as a Result.

function LWord_EncodeEx(const Value:Cardinal; PrefixBits:Byte=8):RtcByteArray;

This function does the same as the "LInt_EncodeEx" function, but only accepts an unsigned 32-bit integers (Cardinal) as input "Value".

function PosWEx(const c,s:RtcWideString):integer; overload;

1-based "at" and Result (WideString)

function PosWEx(const c,s:RtcWideString; at:integer):integer; overload;
 
function PosEx(const c,s:RtcString):integer; overload;

1-based "at" and Result (String)

function PosEx(const c,s:RtcString; at:integer):integer; overload;
 
function PosEx(const c:RtcString; const s:RtcByteArray):integer; overload;
 
function PosEx(const c:RtcString; const s:RtcByteArray; at:integer):integer; overload;
 
function PosEx(const c:RtcChar; const s:RtcString):integer; overload;
 
function PosEx(const c:RtcChar; const s:RtcString; at:integer):integer; overload;
 
function PosEx(const c,s:RtcByteArray):integer; overload;

0-based "at" and Result

function PosEx(const c,s:RtcByteArray; at:integer):integer; overload;
 
function LWord2Str(i:Cardinal):RtcString;
 
function Int2Str(i:integer):RtcString; overload;
 
function Int2Str(i:int64):RtcString; overload;
 
function Int2Hex(i,l:integer):RtcString; overload;
 
function Int2WStr(i:int64):RtcWideString;
 
function Str2Int(const s:RtcString):integer; overload;
 
function Str2Int(const s:RtcWideString):integer; overload;
 
function Str2IntDef(const s:RtcString; def:integer):integer; overload;
 
function Str2LWord(const s:RtcString):Cardinal; overload;
 
function Str2LWordDef(const s:RtcString; def:Cardinal):Cardinal; overload;
 
function Str2Int64(const s:RtcString):Int64; overload;
 
function Str2Int64Def(const s:RtcString; def:int64):int64; overload;
 
function LWordTo6bit(const i: Cardinal):RtcString;
 
function LWordFrom6bit(const r: RtcString):Cardinal;
 

Types

TRtcFileHdl=THandle;
 
TRtcFileAccessMode = (...);

File Access Mode

Values
  • rtc_ShareDenyNone: Allow other apps to read and write to the same file
  • rtc_ShareDenyWrite: Allow other apps to read, but not to write to the file
  • rtc_ShareExclusive: Deny all access to the file - exclusive access mode!
RtcWideString = rtcTypes.RtcWideString;

Unicode String

RtcWideChar = rtcTypes.RtcWideChar;

Unicode character

RtcString = rtcTypes.RtcString;

8-bit Character String (NOT UNICODE!)

RtcChar = rtcTypes.RtcChar;

8-bit Character (NOT UNICODE!)

RtcByteArray = rtcTypes.RtcByteArray;

Array of Bytes

TRtcStrFixType = (...);

"Fix" Types for RTC_STRING_FIXMODE

Values
  • rtcStr_NoFIX: Do NOT modify RtcString data when converting to/from RtcByteArray
  • rtcStr_FixDown: Replace Unicode characters above #255 with ANSI when converting RtcString to RtcByteArray
  • rtcStr_FixUpDown: rtcStr_FixDown option + Replace ANSI characters with Unicode when converting RtcByteArray to RtcString
TRtcWaitResult = TWaitResult;
 
RtcUnicodeToAnsiFunc = function(Chr:Word):Byte;

function type used for Unicode to ANSI code conversions

RtcAnsiToUnicodeFunc = function(Chr:Byte):Word;

function type used for ANSI to Unicode code conversions

RtcAnsiCodePages = (...);

By default, RTC will be using code-page cpWin1252 (Latin I) for implicit Unicode to ANSI conversions. To change the code-page used by RTC (use a different convertion), you have two options:

A) If you need one of the code-pages listed above, simply use the function "RtcSetAnsiCodePage" and set the code-page which you want to be used from this point on.

B) If support for the code-page you need is NOT included, then you can implement your own functions similar to the "RtcUnicodeToAnsiCharWin1252" and "RtcAnsiToUnicodeCharWin1252" functions provided below (implementation section), then assign their addresses to global "RtcUnicodeToAnsiChar" and "RtcAnsiToUnicodeChar" variables (function pointers). NOTE: Only conversions for single-byte ANSI code-pages can be implemented.

To define how implicit Unicode<->ANSI conversions should work, use "RTC_STRING_FIXMODE" and "RTC_STRING_CHECK" variables.

By default, RTC_STRING_MODE will be set to rtcStr_FixDown and RTC_STRING_CHECK will be FALSE, which means that implicit conversions will automatically be done from Unicode Strings to ANSI, but NOT in the other direction and there will be NO exceptions if a Unicode character is found which can NOT be mapped to the current ANSI code-page.

Values
  • cpNone: no conversion
  • cpWin1250: Central Europe (windows-1250)
  • cpWin1251: Cyrillic (windows-1251)
  • cpWin1252: Latin I (windows-1252)
  • cpWin1253: Greek (windows-1253)
  • cpWin1254: Turkish (windows-1254)
  • cpWin1255: Hebrew (windows-1255)
  • cpWin1256: Arabic (windows-1256)
  • cpWin1257: Baltic (windows-1257)
  • cpWin1258: Vietnam (windows-1258)
  • cpWin874: Thai (windows-874)
  • cpISO8859_1: Latin 1 (iso-8859-1)
  • cpISO8859_2: Latin 2 (iso-8859-2)
  • cpISO8859_3: Latin 3 (iso-8859-3)
  • cpISO8859_4: Baltic (iso-8859-4)
  • cpISO8859_5: Cyrillic (iso-8859-5)
  • cpISO8859_6: Arabic (iso-8859-6)
  • cpISO8859_7: Greek (iso-8859-7)
  • cpISO8859_8: Hebrew (iso-8859-8)
  • cpISO8859_9: Turkish (iso-8859-9)
  • cpISO8859_15: Latin 9 (iso-8859-15)

Constants

RTC_INVALID_FILE_HDL = INVALID_HANDLE_VALUE;
 
WAIT_INFINITE = Cardinal($FFFFFFFF);
 
wr_Signaled=wrSignaled;

Infinite timeout

wr_Timeout=wrTimeout;
 
wr_Abandoned=wrAbandoned;
 
wr_Error=wrError;
 

Variables

AppFileName:RtcWideString='';

Full Name of the application or extension in which RTC is running.

SOCK_PACKET_SIZE:integer=1460;

Default Packet Size used by Socket APIs

SOCK_SEND_BUFFER_SIZE:integer=1460*44;

Buffer used by Socket APIs to buffer outgoing data

SOCK_READ_BUFFER_SIZE:integer=1460*44;

Buffer used by Socket APIs to buffer incoming data

SOCK_MAX_SEND_SIZE:integer=1460*44;

Max packet size sent out at once

SOCK_MAX_READ_SIZE:integer=1460*44;

Max packet size read at once

SOCK_RECV_TIMEOUT:integer=1000*60*30;

Maximum socket Receive Timeout in miliseconds

SOCK_SEND_TIMEOUT:integer=1000*60*30;

30 minutes timeout (silly number here, since we want time unlimited) Maximum socket Receive Timeout in miliseconds

SOCK_LISTEN_BACKLOG:integer=200;

30 minutes timeout (ridicilous number, since we want time unlimited) Listenin Socket "backlog" (max. connections waiting to be accepted)

RTC_WAIT_BEFORE_RECONNECT:integer=20;

RTC_WAIT_BEFORE_RECONNECT sets the Sleep period (here in miliseconds) for Reconnect.
This parameter will be used to force a Sleep() before a new reconnect, independent of the "OnReconnect.Wait" parameter.

RTC_WAIT_BEFORE_RESTART:integer=100;

RTC_WAIT_BEFORE_RESTART sets the Sleep period (here in miliseconds) for Restart.
This parameter will only be used if RestartOn.Wait<=0.

RTC_WAITFOR_RELEASE_PROVIDER:integer=15;

RTC_WAITFOR_RELEASE_PROVIDER is the maximum time (in seconds) allowed for any connection component to wait for its connection provider to be released.

RTC_WAITFOR_PROVIDER_FINISH:integer=50;

Time to wait (in milliseconds) after releasing a connection provider for background thread to finish.

RTC_WRITE_RETRIES:integer=0;

Default number of times to automatically retry "Write_File" and "Write_FileEx" operations if they fail.

RTC_WRITE_RETRY_DELAY:integer=100;

Default number of milliseconds to wait between each retry attempt in "Write_File" and "Write_FileEx" functions.

RTC_DEFAULT_TEMP_FOLDER:RtcWideString='';

Default Folder used when creating Temporary files ("GetTempFile" function). If empty (not specified), the '/TEMP' folder is acquired from the OS.

RTC_STRING_FIXMODE:TRtcStrFixType=rtcStr_FixDown;

RtcString "fix" mode (rtcStr_NoFix, rtcStr_FixDown, rtcStr_FixUpDown)

RTC_STRING_CHECK:boolean=False;

Raise an exception if conversion from RtcString to RtcByteArray would result in data loss

RTC_INVALID_CHAR:byte=63;

Character to be used as a replacement for all Unicode characters not in the current ANSI codepage

RtcUnicodeToAnsiChar:RtcUnicodeToAnsiFunc=nil;

Pointer to the function used for Unicode to ANSI character conversions

RtcAnsiToUnicodeChar:RtcAnsiToUnicodeFunc=nil;

Pointer to the function used for ANSI to Unicode character conversions


Generated by PasDoc 0.14.0.