English 中文(简体)
Using Protocol buffer as general Data object?
原标题:

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.

最佳回答

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.

问题回答

In general, I design the layers of my systems so that implementation details from one layer don t leak into one another. I don t have direct experience of Google s Protocol Buffers, but it sounds like you want to use the same representation for the transport and at higher layers of your system.

If you decided you wanted to stop using Protocol Buffers as the transport representation, how easy would it be to use something else?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签