#1 2018-04-07 10:22:09

EgorovAlex
Member
Registered: 2015-02-18
Posts: 43

Record serialization on Mac and Linux

Hello,

Where I can find any examples or documentation for serialization on Delphi for records on Mac, Linux and Android?
This is possible?

I need analogs of RecordLoadJSON and RecordSaveJSON on Windows platform

Last edited by EgorovAlex (2018-04-07 19:59:32)

Offline

#2 2018-04-07 11:31:43

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: Record serialization on Mac and Linux

What do you mean by reserialization?

All documentation is at https://synopse.info/files/html/Synopse … 01.18.html

Explanation for record saving/loading is at 10.1.3

Offline

#3 2018-04-07 15:10:01

EgorovAlex
Member
Registered: 2015-02-18
Posts: 43

Re: Record serialization on Mac and Linux

This was typing error. Fixed.
I need this functions for cross-platform delphi compiler

Last edited by EgorovAlex (2018-04-07 16:15:34)

Offline

#4 2018-04-08 11:54:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Record serialization on Mac and Linux

They don't exist yet in SynCrossPlatform units.
Since for our internal purpose, which is SOA clients, we generate the code using Mustache templates to make fast serialization/deserialization.

Offline

#5 2018-04-08 15:23:10

EgorovAlex
Member
Registered: 2015-02-18
Posts: 43

Re: Record serialization on Mac and Linux

Can you provide any short and simle example to do that?
Read about Mustache usage but did not understand how to use it for this purpose

Offline

#6 2018-04-08 21:40:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Record serialization on Mac and Linux

Offline

#7 2018-04-11 07:18:57

EgorovAlex
Member
Registered: 2015-02-18
Posts: 43

Re: Record serialization on Mac and Linux

This is my current realization for client or this can be faster?:

type
  TRec = record
    type
      TSQLRec = class(TPersistent)
      private
        fName: string;
        fDate: TDateTime;
        fInt : UInt16;
      published
        property Name: string    read fName write fName;
        property Date: TDateTime read fDate write fDate;
        property Int : UInt16    read fInt  write fInt;
      end;
  public
    Name: string;
    Date: TDateTime;
    Int : UInt16;
    procedure FromJSON(const AJSON: string);
    function  ToJSON: string;
  end;

{ TRec }

procedure TRec.FromJSON(const AJSON: string);
var
  lRec: TSQLRec;
begin
  lRec := TSQLRec.Create;
  try
    if JSONToObject(lRec, AJSON) then begin
      Name := lRec.Name;
      Date := lRec.Date;
      Int  := lRec.Int;
    end;
  finally
    lRec.Free;
  end;
end;

function TRec.ToJSON: string;
var
  lRec: TSQLRec;
begin
  lRec := TSQLRec.Create;
  try
    lRec.Name := Name;
    lRec.Date := Date;
    lRec.Int  := Int;
    Result := ObjectToJSON(lRec);
  finally
    lRec.Free;
  end;
end;

Offline

#8 2018-04-11 07:48:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Record serialization on Mac and Linux

For the SynCrossplatform client, you may just use a local TJSONVariantData instead of the TSQLRec.
But I am not sure it will be noticeably faster...

Offline

Board footer

Powered by FluxBB