Java and Google protocol buffers: does anyone have a simple example of getting started with this?

I'm not sure where to start.

For example, some sites that I saw wanted me to install maven and do a bunch of things with copying files to system directories and add these directories to $ path (which I hate doing, by the way, developers should just write the installer). But in any case, the library should be packed with my application, so I'm not interested in setting protocol buffers ... Just attack it in the java project in eclipse. (for example, adding cans to the build path.)

Any guides you guys know about?

+4
source share
2 answers

You do not need to make any installations on production boxes. You need to install it in the build window so that you can create java bindings for the .proto file you are writing. This is similar to a way to generate code from wsdl or xsd. When you generated the code (which helps in serializing / deserializing the binary message), you can link it as a jar and use it like any other jar library. Here is a short tutorial to get you started.

Just add more clarity.

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

The process is as follows

  • Create .proto file with meta information
  • run .proto via protoc.exe to generate code
  • Combining the generated code into a jar file (or just importing all this code into the source tree).
  • Add jar file to create path
  • Use the generated code in the application for ser / deser

Using maven greatly simplifies 2, 3, and 4

+4
source

Hope this helps.

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

Also gives a few words about setting up Eclipse at the end

0
source

Source: https://habr.com/ru/post/1335474/


All Articles