Class Properties to/from MemoryBlock

Hi there,
Does any of you pros know if it would be possible to create a Class consisting of a number of Properties and the have a Method that runs through all properties and merges all properties data into a MemoryBlock for HTTP POST?, And then have it read back into the Class at the Server side?

Something like a binary JSON

The Class would be an external type, so that both iOS and Web APP can access the same Class

[quote=488787:@Bobby Kurell]Hi there,
Does any of you pros know if it would be possible to create a Class consisting of a number of Properties and the have a Method that runs through all properties and merges all properties data into a MemoryBlock for HTTP POST?, And then have it read back into the Class at the Server side?

Something like a binary JSON
[/quote]

Short answer is yes… Besides coming up with a format for all data types (which i did) , to make the code general for any class one would need to use introspection to do the serialization. You also need to decide if you want to serialize all properties or just public ones.
If one is supporting b array oaf records, depending on size you might want to Gzip te payload too… I wrote code that could either send it unzipped, All Gziped or Gzipping in blocks of x records for when memory is tight on client or server.

-karen

Also see my Data Serialization example project:

https://github.com/ktekinay/Data-Serialization

[quote=488789:@Karen Atkocius]Short answer is yes… Besides coming up with a format for all data types (which i did) , to make the code general for any class one would need to use introspection to do the serialization. You also need to decide if you want to serialize all properties or just public ones.
If one is supporting b array oaf records, depending on size you might want to Gzip te payload too… I wrote code that could either send it unzipped, All Gziped or Gzipping in blocks of x records for when memory is tight on client or server.

-karen[/quote]
Good idea on the Public Properties in order to have ‘Internal’ variables. Perhaps I’m thinking too simple (or it might not be possible), but I was thinking:

Method ToMemBlock
Var mb As MemoryBlock(0)
Var bs as BinaryStream(mb)

for each p in class
If p.Scope = Public
Select case p.Type

Case Integer
bs.WriteInt64
Case Double
bs.WriteDouble


end Select
end if

Return mb

And the have the opposite. The Issue will be Arrays or Properties with another ClassType, and the ‘For each’ needs to have the same order of Properties always (per build)

would this work?

Is doable, I already had a class in a working project, I called “BinaryMessage”, but, doesn’t work on iOS because the String type, could be easy implement the Text type.

You need a way to ‘encode’ the data, you can check out my encoding here.