Jump to content
o815

serialize/deserialize data with RTTI

Recommended Posts

Hi there,

 

I was just wondering if anyone of you is using a cool de/serialization library (not JSON, something more "binary").

I am looking for something compact and want to avoid as much extra code as possible.

 

Currently we are using (in my optionion (until now)) the coolest library:

https://github.com/KrystianBigaj/kblib

 

Note: Only cool if you don't use the de/serialized data out of delphi universe.

 

What I like on this library, I can use just ONE LINE to de/serialize my structs (including Arrays etc):

 

type

 

 

//example definition of my data I want to de/serialize

TStruct2 = record

 blabla : string;

 bla : boolean;

end;

 

TMyStruct = record

  foo : integer;

  foo2 : string;

  foo3 : TArray<Integer>;

  foo4 : TArray<TStruct2>;

end;

 

 

 

...

var

s : TMemorystream;

foo : TMyStruct;

...

 

TKBDynamic.ReadFrom(s, foo , TypeInfo(TMyStruct));  // serialize data to memorystream

TKBDynamic.WriteTo(s, foo , TypeInfo(TMyStruct));     // deserialize data from memorystream

 

Does anybody out there know any similar and compact library (f.e. BSON) which can be easily used with a single line?

 

When I look around, there is only something like this, which is too much overflow (in my opinion):

https://docwiki.embarcadero.com/RADStudio/Alexandria/en/BSON

 

 

Any suggestions?

Share this post


Link to post
1 hour ago, o815 said:

Any suggestions?

Ask a programmer to convert that BSON example into an universal one-liner class method.

Share this post


Link to post
On 5/5/2023 at 11:48 PM, timfrost said:

You might like the Grijjy implementation of Google Protocol Buffers: https://blog.grijjy.com/2017/04/25/binary-serialization-with-google-protocol-buffers/

Yeah man, that looks nice, thanks! I'll give it a try.

 

I also found another interesting git project which supports a lot of serialization standards (but still a work in progress):

https://github.com/SeanSolberg/DynamicDataObjects

 

JSON,
BSON,

MsgPack (similar to "protocol buffer")

....

 

 

Edited by o815

Share this post


Link to post
22 hours ago, Rollo62 said:

Thanks, I have seen this library, too.

Problem is that BSON (or only this BSON library) is not supporting dynamic arrays:

 

Quote

Features

The serialization engine supports the following features:

       [...]

  • You can also serialize dynamic arrays to JSON (but not to BSON and TgoBsonDocument).

I am using now the Grijjy implementation of Google Protocol Buffers which was suggested by "timfrost".

The only uncool thing is that protocol buffers is not supporting 2D arrays (TArray<TArray<...>>) and TDatetime.

TDatetime seems to be supported by the latest update of protocol buffer specification, but is not updated by Grijjy until now.

 

 

BTW: I found another library which supports "messagepack". There's also a community version for free (but didn't test it):

http://www.components4developers.com/products_kbmMW.html

Edited by o815

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×