Protocol buffers

Clients and servers communicate with each other by sending messages encoded in a protocol. When we wrote Realm of the Mad God, Alex Carobus and I made up our own protocol. We designed it by hand to be small and fast, and it worked very well. But there was one major drawback: every time we wanted to augment or change the protocol, we had to go in and hand-edit a bunch of code in both the client and the server, and then record what we did in the protocol definition documentation. If we neglected to update one of the three, or if the changes did not match exactly, we were in trouble.

Google has built software called Protocol Buffers to help with exactly this problem. The protobuf system lets you write one file (the proto file), which serves as definition and documentation for the protocol. The system uses a "protocol compiler" to read the proto file and generate the client and server code. When you need to change the protocol, you edit the proto file, run the protocol compiler, and you're done.

Google's protocol compiler generates C++, Java or Python code. Although Jetbolt's MMO uses C++ for the server, its client is written in Actionscript 3 (AS3). To make the protocol compiler emit AS3, I had to track down an open source plugin called protoc-gen-as3 and massage it gently until everything worked. But once that was done, protocol changes were super fast and easy to make. Hooray!