Title: Best way to serialize a TObject from Server to client Post by: ClementDoss 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 Title: Re: Best way to serialize a TObject from Server to client Post by: D.Tkalcec (RTC) 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" (https://www.google.com/webhp?#q=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 |