Indy 9
TIdEncoder3to4
Hierarchy, Properties, Methods, See Also, Unit: IdCoder3To4
Implements an encoder using a table-driven alphabet to produce output represented in the US-ASCII character set.
TIdEncoder3to4 = class(TIdEncoder)
Unit
IdCoder3To4
Description
TIdEncoder3to4 is a TIdEncoder descendant that provides encoding capabilities that represents arbitrary sequences of byte data in a form that need not be humanly readable. TIdEncoder3to4 is almost identical to the mechanism used in Privacy Enhanced Mail (PEM) applications, as defined in RFC 1421 (http://www.rfc-editor.org/rfc/rfc1421.txt) .

TIdEncoder3to4 provides a coding table to represent the valid characters in the encoder alphabet. Note: TIdEncoder3to4 does not specify the valid characters in the coding table. Application will generally use a descendant class, like TIdCoderMIME or TIdCoderUUE, where the alphabet is specified.

TIdEncoder3to4 represents 3-byte input values as 4 concatenated 6-bit groups, each of which is translated into a single valid character in the encoder coding table.

Special processing is performed to ensure that data to be encoded is a multiple of 3-bytes. When fewer than 3 bytes are available, a user-definable fill character is used to pad input data to the required length.


TIdEncoder3to4.CodingTable
TIdEncoder3to4, See Also
Specifies the valid characters for the encoder alphabet.
property CodingTable: string;
Description
CodingTable is a read-only String property that identifies the valid characters for the encoder. Note: TIdEncoder3to4 does not specify the valid characters in CodingTable. Application will generally use a descendant class, like TIdCoderMIME or TIdCoderUUE, where the alphabet is specified.

TIdEncoder3to4.FillChar
TIdEncoder3to4, See Also
Character used to pad input values to the encoder.
property FillChar: Char;
Description
FillChar is a Char property that identifiers the value to be used to pad the length of an input stream. FillChar is used in Encode to pad the input stream to the required multiple of three for the encoding algorithm.

TIdEncoder3to4.Encode
TIdEncoder3to4, See Also
Implements the encoding algorithm used to represent arbitrary octet sequences in the 7-bit US-ASCII character set.
function Encode(ASrcStream: TStream; const ABytes: Integer = MaxInt): string; override;
Parameters
ASrcStream: TStream
Stream containing the values to be encoded.
const ABytes: Integer = MaxInt
Number of bytes in ASrcStream to be encoded. Default value is MaxInt.
Return Value
String - Encoded values for data in the input stream.
Description
Encode is an overridden String function in TIdEncoder3to4 that reimplements the inherited function to provide the encoding algorithm used to represent arbitrary octet sequences in the 7-bit US-ASCII character set.

ASrcStream represent a TStream descendant that contains the values to be encoded. Note: Encode does not reset the position of ASrcStream prior to or following the process of reading values from the stream.

ABytes is an Integer that represents the number of bytes in ASrcStream to be encoded. The default value for ABytes is MaxInt. If a value other than MaxInt is specified, ABytes must be a multiple of 3 or an EIdException will be raised with the RSUnevenSizeInEncodeStream message. When ABytes contains the value MaxInt, the user-defined FillChar will be appended to the input stream until the length is the required 3 bytes.

Encode calls the EncodeUnit method using the 3 bytes values read from the stream to generate the encoded value written to the result String.


TIdEncoder3to4.EncodeUnit
TIdEncoder3to4, See Also
Converts 3 byte input values to their Cardinal representation.
procedure EncodeUnit(const AIn1: Byte; const AIn2: Byte; const AIn3: Byte; var VOut: Cardinal);
Parameters
const AIn1: Byte
First input byte value.
const AIn2: Byte
Second input byte value.
const AIn3: Byte
Third input byte value.
var VOut: Cardinal
Cardinal representation of the encode value.
Description
EncodeUnit is Procedure that converts the 3 byte input values (AIn1, AIn2, AIn3) to their encoded Cardinal representation in VOut. EncodeUnit uses the Ordinal values from CodingTable to represent each consecutive 6-bit value in the 3-byte input parameters.

EncodeUnit is called repeatedly from Encode as inoput values are read from a stream.


Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.