Summary

TBinaryData is a built-in serialization engine type, which allows to serialize and de-serialize binary data.

Syntax

TBinaryData = record

Methods

 NameDescription
Create(TStream)

This overload of Create method family allows to initialize TBinaryData instance with TStream object, which contains real binary data.

Create(string)

This overload of Create method family allows to initialize TBinaryData instance with binary data, encoded as a Base-64 string.

Create(TGetDataFunc)

This overload of Create method family allows to initialize new  TBinaryData instance with NG.Serialization.TGetDataFunc user callback function reference. This generally allows to read binary data from any data source without storing arbitrary sized binary data in memory.

Create(Void Type,Integer)

This overload of Create method family allows to initialize TBinaryData instance with in-memory stored binary data.

Read(TStream)

This overload of Read method family allows to read binary data from NG.Serialization.TBinaryData instance into destination TStream object.

Read(Void Type,Integer)

This overload of Read method family allows to read binary data from NG.Serialization.TBinaryData instance.

SkipAll

SkipAll method allows to skip all binary data contained in NG.Serialization.TBinaryData instance.

ToBase64

ToBase64 method allows to retrieve all binary data represented by NG.Serialization.TBinaryData instance as a Base-64 encoded string.

Top

Remarks

Binary data can be serialized by initializing TBinaryData variable using one of TBinaryData constructors and passing it into TSerializer.Value procedure. Initializing TBinaryData record can be performed using one of its overloaded constructors, which allow to get the data from user implemented callback, in memory data buffer or Base-64 encoded string.

Binary data can be de-serialized by getting an instance of TBinaryData from TDeserializer.Value function. After that the data can be read into user buffer using NG.Serialization.TBinaryData.Read(Void Type,Integer) method.

TBinaryData is built into serialization engine, thus allowing to manipulate binary data using usual TSerializer.Value and TDeserializer.Value  methods.

TBinaryData acts as a read-stream, so, every call to its NG.Serialization.TBinaryData.Read(Void Type,Integer) method will read next chunk of data. So, its generally impossible to use same TBinaryData instance more then ones; this implies that TBinaryData should not be used as a field type. Properties of TBinaryData type are, however, allowed; but, at each property read the property should return newly initialized TBinaryData instance.

Note:

In most cases TBinaryData record acts only as a wrapper for underlaying data and does not really contain all data. Thus, its not valid, for example, to get an instance of TBinaryData record from de-serializer and store it for a long time; all data should be read from the instance before any subsequent call to de-serializer.

Examples

DelphiCopyCode imageCopy Code
type
  TMyObject = class
  private
    FData: array[0..255] of Byte;
    function GetData: TBinaryData;
    procedure SetData(const Value: TBinaryData);
  public
    property Data: TBinaryData read GetData write SetData;
  end;

function TMyObject.GetData: TBinaryData;
begin
  Result := TBinaryData.Create(FData, SizeOf(FData));
end;

procedure TMyObject.SetData(const Value: TBinaryData);
begin
  Value.Read(FData, SizeOf(FData));
end;

See Also