It works, but the fields that are exclusive to the extended structure type don't get serialized. I want to have a generic function I can just throw and basic Packet type at and get a JSON-formatted version of it, including all its child fields. I'm writing an app that's going to need many different types of packets and this is what came to mind right away, but it doesn't work. Does anyone here have advice on how to make this work, or better ways to accomplish the same goal?
Thanks,
Quin,.
I don't think that doing it exactly the way you want is currently possible with PureBasic. Maybe the easiest way is to implement MakePacketJSON() as Macro rather than as procedure.
I just had another idea: Pass a generic pointer and an additional 'type' parameter to the procedure MakePacketJSON(). Unfortunately, we can't pass a structure name as parameter to a procedure.
Very nice! I think I still prefer the macro, but this is a neat approach as well.
I wish we could pass a structure name to a procedure like you can to AllocateStructure, InsertJSONStructure etc. from actual PB code. If we could I would just make the function take a structure name as the second parameter instead of a type, so no select is needed. Maybe something for the wishlist.
This is a case where jsonRuntimeStructure support would be useful, it's what I'm using for my db engine so it can get and set arbitrary user structures via runtime reflection using a string of the type rather than the compile time structure.
so rather than using a bunch of selects on users types to marshal the structures it can be done at runtime.