优秀的数据序列和还原类----TSimpleMsgPack

优秀的数据序列和还原类----TSimpleMsgPack

TSimpleMsgPack是D10天地弦的作品。

优点:至简,就一个单元文件实现,不需要引用其他单元。

缺点:不是标准的MSGPACK实现,不能跨语言兼容。

所以:TSimpleMsgPack只能用于DELPHI开发,不能用于其他语言。

而QDAC的QMsgPack却是标准的MSGPACK实现,能跨语言兼容。

有了它,从此数据的序列和还原不再是梦魔。

适用极广:可以适用于所有版本的DELPHI,不论D7还是最新的XE10.1,都支持。激动!

封装极简:完全独立的一个单元即可,不需引用任何其它的单元。

用法极简:调用非常简单。

其支持的序列的数据格式非常丰富。

下面列出该类的一些常用的接口方法:

procedure LoadBinaryFromStream(pvStream: TStream; pvLen: cardinal = 0);
procedure SaveBinaryToStream(pvStream:TStream);

procedure LoadBinaryFromFile(pvFileName:String);
procedure SaveBinaryToFile(pvFileName:String);

procedure EncodeToStream(pvStream:TStream);
procedure EncodeToFile(pvFileName:string);


procedure DecodeFromStream(pvStream:TStream);
procedure DecodeFromFile(pvFileName:string);

function EncodeToBytes: TBytes;
procedure DecodeFromBytes(pvBytes:TBytes);

function Add(pvNameKey, pvValue: string): TSimpleMsgPack; overload;
function Add(pvNameKey: string; pvValue: Int64): TSimpleMsgPack; overload;
function Add(pvNameKey: string; pvValue: TBytes): TSimpleMsgPack; overload;
function Add(pvNameKey: String): TSimpleMsgPack; overload;
function Add():TSimpleMsgPack; overload;

function ForcePathObject(pvPath:string): TSimpleMsgPack;

/// <summary>
/// remove and free object
/// false : object is not found!
/// </summary>
function DeleteObject(pvPath:String):Boolean;

property AsInteger:Int64 read getAsInteger write setAsInteger;
property AsString:string read getAsString write setAsString;
property AsBoolean: Boolean read GetAsBoolean write SetAsBoolean;
property AsFloat: Double read GetAsFloat write SetAsFloat;
property AsSingle: Single read GetAsSingle write SetAsSingle;
property AsDateTime: TDateTime read GetAsDateTime write SetAsDateTime;
property AsVariant: Variant read GetAsVariant write SetAsVariant;

property AsBytes: TBytes read GetAsBytes write SetAsBytes;

property O[pvPath: String]: TSimpleMsgPack read GetO write SetO;
property S[pvPath: String]: string read GetS write SetS;
property I[pvPath: String]: Int64 read GetI write SetI;
property B[pvPath: String]: Boolean read GetB write SetB;
property D[pvPath: String]: Double read GetD write SetD;

property Items[AIndex: Integer]: TSimpleMsgPack read GetItems; default;

posted @ 2016-10-27 16:54  delphi中间件  阅读(1056)  评论(0编辑  收藏  举报