开发者

Java & Google Protocol Buffers: Does anyone have a simple example of getting started with this?

开发者 https://www.devze.com 2023-02-04 11:33 出处:网络
I\'m not really sure开发者_JAVA技巧 where to start. Like, some sites I saw wanted me to install maven, and do a bunch of things with copying files to system directories, and adding those directories

I'm not really sure开发者_JAVA技巧 where to start.

Like, some sites I saw wanted me to install maven, and do a bunch of things with copying files to system directories, and adding those directories to $path (which I hate doing, btw, the devs should just write an installer). But anyway, the library needs to be packaged with my app, so I'm not interested in installing Protocol Buffers... Just attacking it to my java project in eclipse. (like, adding jars to the build path.)

Any tutorials you guys know of?


You don't need to do any installation on production boxes. You need to install it on the build box so that you can create java bindings for the .proto file you write. This is similar to the way you generate code from wsdl or xsd. Once you the the generated code (that helps in serialize/deserialize of the binary message), you can bundle it as a jar and use it like any other jar library. Here is a small tutorial to get you started.

Just to add more clarity

Protobuf   = XML Schema
.proto     = xsd
protoc.exe = xjc

The process is as follows

  1. Build a .proto file that provided meta info
  2. run the .proto through the protoc.exe for it to generate code
  3. Bundle the generated code into a jar file (or just import all that code to your source tree)
  4. Add the jar file to build path
  5. Use the generated code in your application for ser/deser

Using maven greatly simplifies 2, 3 and 4


Hope this would help.

Describes how to convert ProtoBuf schema into java File http://hecktechsolutions.blogspot.in/2015/01/protocol-buffer.html

Also gives few words on Eclipse Setup at End

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号