I have to receive data from server. Server's application is written in VS2008 (MFC). There is only one way to send this data from server -> as CArchive object. I can't change server source.
I want to receive this data in PHP (by tcp), and convert them to JSON. Is it any smart way to convert CArchive to JSON?
CArchive
doesn't have a predefined format that you can parse. It's just a binary file which is application dependent. You have to know what is in it to know how to read it. A library could make it easier to read some data types (CString
, CArray
, etc.) but I'm not sure you'll find anything like this.
The following example shows how CArchive
works (storing part):
CArchive ar;
int i = 500;
float f = 10.4f;
CString str(_T("string"));
ar << i << f << str;
So you would have to read binary data and somehow interpret it. This is easy in C++ because MFC frameworks knows exactly how to serialize types, including complex types like CString
and CArray
. But you'll have to do this on your own using PHP.
For example you might read 4 bytes at specified offset and interpret it as int
. Next four bytes for float
. And then you have to see how to load CString
, it stores the length first and then data, but you'll have to take a look at the exact format it uses.
There is no ready-to-go/use CArchive
-> JSON converter. I'd suggest you to modify your server code to produce both CArchive
and JSON data.