Google Protocol Buffers Java
I hope you are familiar with Google Protocol Buffers and now a days its quite popular in the industry. In this tutorial I will show how to user Google Protocol Buffer using Java to read and write messages.
- Protocol buffer compiler which is already included in project download link
- JDK 1.8
- Eclipse any version
- Maven latest version
- Create Maven project name: GoogleProtoBuff and below is final structure:
- First thing you need to do is define message formats in a .proto file. In this example I have created three .proto file to understand better how to create it:
- Next you will have to generate java class out of it, You will need protocol butter compiler which you could download from here but if you download complete project from below download link you don’t need to do it as I have included in the project. Please user command mentioned in “readme.txt” file:
- Open command prompt from and use above command individually to generate java file as sample below in my case:
- Use all three command you will see file generate in below package (Don’t forget to refresh your project to see generate files):
- Now read and write Protocol butter object use below class:
- Above I have showed you message conversion only for one protocol message you could use same technique for another protocol message.
Download project: GoogleProtoBuff