Binary serialization is no fun

I’m currently working on an iPad project that communicates with Java service. Nothing fancy, right? Yet, instead of using JSON or XML, communication goes using AMF protocol with binary serialization. Doesn’t sound scary at all, binary serialization is fast, output is small, we all like it, right?
Now, I didn’t get any automatically generated classes that I can synchronise with service in few clicks, like I could do with WCF. I got some classes generated by developer who was taking care of the project before, but those classes got a little bit outdated recently. There is possibility to convert Java classes into Objective-C code using some converter that this guy wrote, but it’s not perfect, it would take me some time to fix some issues from autogenerator. But more important, if something breaks down it takes so much time to find out what is wrong.
Few days back I was trying to figure out what went wrong so I can no longer deserialize data from service. In world of XML you look at elements, attributes and it’s pretty easy most of the time to find out what’s wrong. If XML has some additional attributes or elements, serialization usually don’t care or at least gives you clear error message saying what is wrong, which piece you are missing. Binary serialization – it don’t. You just get some pieces of binary data and convert them into objects hoping everything will go right. Of course AMF helps you with that up to some point, but not always.
So I was trying to fix this problem. Watching binary data, trying to figure out what’s going on. One thing that helped me was library reported object of type 78. Clearly, this didn’t fell into enum values, which start me wondering – what could it be? Quick look into ASCII reveals capital ‘N’ letter. Then, next property should be “New” text value. But next property, not the current one. Clearly – I got 2 bytes to far into the data. No need to go into details, but this made me to go to Java service, and piece by piece look through clases to find out which property I missed. And there it was, boolean property that appeared in service class definition.
All this took me some time. Using JSON or XML it would take me minute or two.
My advice – go with JSON or XML to make your life easier. If you think that it’s to big or to slow, thing again. Try to redesign your service, think if you really need to send all this data to client. Probably not. Time saved on coding, debugging, looking for errors – it invaluable. You must have really, really slow device that couldn’t handle parsing normal data formats so you would need to go into binaries.
Save binaries to images, movies and music. Keep data easy to discover, easy to read, easy to use.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s