Jump to content
  • Advertisement
Sign in to follow this  
ElPeque2

Serialization PHP - C++ (boost?)

This topic is 3672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What i need to do is this: Have a php file in a webserver, doing a POST with binary payload to a fast-cgi written in c++, and the c++ should deserialize that payload into a known struct. I've been playing around with boost::serialization, but i can't seem to comprehend the binary format it generates (So i could hardcode the php to make a valid payload to be deserialised from the fast-cgi). And not so important: i've noticed boost::serialization to binary archives always look like: serialization::archive ÃõH@ can't i get rid of the "serialization::archive" thing that is obviusly not part of the struct i just serialized? Thanks a lot for your help. I'd appreciate any other ideas to accomplish the same result :).

Share this post


Link to post
Share on other sites
Advertisement
it can be anything. like...

struct whatever
{
int a;
int b;
float c;
std::vector<int> d;
}

(mainly structs consisting of basic types and collections of basic types)

i'm trying to implement something like an RPC or webservice. and the struct would be mainly a way to pass all the parameters in a binary manner, so i could either just cast it to the struct i know it is, or deserialize it with boost::serialization, or something like that :).

did i make myself clear?

thanks for your time :)

Share this post


Link to post
Share on other sites
I see. In that case, I would suggest using an XML serialization format, and compressing it. XML is easier to parse (and more standard) than binary formats, yet not really heavier when compressed, plus boost should be able to read it.

Alternately, you may design your own archive format for boost.

Share this post


Link to post
Share on other sites
i see.

xml is not an option for now. im actually doing all this to bypass using a webservice/SOAP/xml, etc.

this should be real fast :)

i'll take a look at making my own archive type. i hope it's not very complicated, otherwise ill have to do something uglyer, like casting :P.

Share this post


Link to post
Share on other sites
Quote:
Original post by ElPeque2
i'll take a look at making my own archive type. i hope it's not very complicated, otherwise ill have to do something uglyer, like casting :P.


Casting wouldn't work, for endianness reasons. This is precisely what boost allows you to circumvent.

Share this post


Link to post
Share on other sites
Ice.

Quote:
this should be real fast :)


In what way? You'll need to be on gigabit network before PHP + C++ combined become a bottle-neck.

But either way, the overhead of HTTP (edit), or the size of payload will determine the cost, very rarely the encoding.

Share this post


Link to post
Share on other sites
Casting would still be trouble if i will only be using x86 systems? And if i were to migrate, then it would all switch to x64.

And it's interesting what you say about where the bottlenecks would be. My intuition tells me that passing xmls should be very inefficient. (much more data, maybe compress, decode, etc). Any past experiences?

Share this post


Link to post
Share on other sites
Quote:
Original post by ElPeque2

And it's interesting what you say about where the bottlenecks would be. My intuition tells me that passing xmls should be very inefficient. (much more data, maybe compress, decode, etc). Any past experiences?


Let's say you are sending 3 ints over the wire. They take 12 bytes in binary encoding.

The POST looks like this:
POST /some_path HTTP/1.0
Content-type: multipart/form-data, boundary=ABCD
LKHsadfhiueakjhg
--ABCD


First, you need to MIME encode it, which will likely result in increased size of 4/3 (16 bytes).
Second, you need to form a valid POST request (100 bytes).
Third, you need to send this as TCP packet (120 bytes).
Then the IP header (140 bytes).

And suddenly, your compact, optimal, efficient 12 bytes resulted in 140 bytes on the wire.

HTTP isn't designed for efficiency, so unless you're sending proportionally enough data (tens of kilobytes per request), it will be horribly inefficient.

Even more, encoding data as text and passing it as URL parameters in POST will be much more efficient for in many cases, even if not binary encoded.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!