Using Protocol buffer as general Data object?

java, protocol-buffers

Solution

Well, they're not terribly convenient to use that way as they're immutable - you could pass the builders around, but that makes for rather long type names. It also means you're limited to the data types supported by protocol buffers (and your own messages).

It's safe to do this, but it doesn't always create the nicest of designs. On the other hand, sometimes it's just what the doctor ordered :)

I suggest you experiment - there's no "one size fits all" here.

Problem

We're introducing protocol buffers as the new transport for some back end RPC services. Because there's resistance to manually shuttling data between different forms of similar objects, I can forsee the Protocol Buffer instances being passed up the stack a bit higher than just to the RPC server interface. Is this something that I should try to avoid? Is it safe to treat a protocol buffer object like a plain data holder, with the nice convenience that it can quickly and efficiently be transformed into and out of binary? The other reason I see it as being a nice way to generate data objects is that the notion of required/optional fields and the automatically generated builder interface.

Original source