RTC Forums
November 24, 2024, 09:41:46 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Best way to serialize a TObject from Server to client  (Read 4392 times)
ClementDoss
RTC License
***
Posts: 36


« on: October 06, 2014, 06:48:01 PM »

Hi,

I'm working on a project where I'll need to serialize a TObject descendant pass through the wire  and unserialize this object in the client side.

I'm still wondering what would be the best approach. I like to use the TrtcRecord, but I'm afraid there will be more converting than necessary.
Should I serialize the object to a rtcRecord (somehow) and the client side would rebuild the object from a rtcRecord? (By the way, I'll have to write a TObject to rtcRecord converter and a rtcRecord to TObject...)

Or it be better to pass a JSON string using some library to marshall/unmarshall?

I'm looking for the most efficient way of doing this serialization using RTC without reinventing the wheel.

Best regards,
Clément
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: October 06, 2014, 09:47:45 PM »

There is no mechanism in the RTC SDK which would automatically serialize or deserialize a TObject instance.

But ... from the RTC perspective it does not really matter what library you use for serialization and deserialization of the data you are sending and receiving over the wire, so you can either copy the data from TObject to TRtcValue objects in order to have it serialized (do the exact opposite for deserialization), or write your own code to serialize and deserialize data directly from each TObject, or use some 3rd-party library which can handle TObject serialization and deserialization.

If you are looking for pointers on general-purpose TObject serialization and deserialization, googling "delphi tobject serialization" might help. I've never done anything with RTTI, so I can't comment on the performance penalty of using it, but it does seem to be the most efficient solution in terms of "coding time".

From the performance perspective, you might get better results if you write your own serializer and deserializer for each class you need to handle, but if you have a lot of different classes, or if your classes have complex internal structures, this will be tedious work.

Best Regards,
Danijel Tkalcec
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.023 seconds with 17 queries.