Protobuf is a cross-platform message interaction protocol, such as XML, JSON, and so on.
Protocolbuffer (PB) is a format for Google's data interchange, which is independent of the language and is platform independent.
Google offers implementations in multiple languages: Java, C #, C + +, go and Python, each of which contains compilers and library files for the appropriate language.
Because it is a binary format, it is much faster than using XML for data exchange. It can be used in data communication between distributed applications or in heterogeneous environments.
As a good efficiency and compatibility of the binary data transmission format, can be used for such as network transport, configuration files, data storage and many other areas.
Related open source project code on GitHub: http://pan.baidu.com/s/1eSDSb5o
The following shows how to export the PROTOBUF message body to a C # supported. CS Class
First we get the following. proto file
Package Hrv;option java_package = "com.******.****.***.protobuf"; option Java_outer_classname = "Requestproto"; message Request { extensions to max; Enum Type { LOGIN = 0; Change_password = 1; Start_scale = 2; Stop_scale = 3; DATA_PPG = 4; Data_ep = 5; DATA_HRV = 6; Data_ibi = 7; Mark_scale = 8; Resource_list = 9; Update_user_info = ten; Get_scale_list = one; Get_scale = n; } Required type type = 1; Optional string timestamp = 2;}
Then download the Export tool Protogen.exe:http://pan.baidu.com/s/1eriv3oe
Enter into the directory via the cmd command line
Use the following command line to export the. cs file
Protogen.exe -i:request.proto -o:request.cs
Command explanation
Protogen-i:test.proto-o:test.cs-ns:uge. Metadata-p:import=uge This sentence means, input Test.proto file, give me generate Test.cs file, code in namespace Uge. metadata, by the way, using Uge.
Can see in the same directory generated a Request.cs file, this file is the CS class file we want
Request.cs file contents are as follows
View Code
But it's too cumbersome to export from a command line like this, and as a lazy programmer, we're going to use a faster way to generate batches, and this time we think of the bat batch
echo onset path=protogen\protogen.exe%Path% -i:request.proto -o:openapimodel\request.cs%path%-I : Response.proto -o:openapimodel\response.cs%path% -i:userinfo.proto -o:openapimodel\userinfo.cs% path% -i:loginreq.proto -o:openapimodel\loginreq.cs%path% -i:loginresp.proto -o:openapimodel \loginresp.cspause
The above batch file will all the. proto files into a. cs class file.
Or go directly through all the. prot files under a folder, convert all
@echo offset path=protogen\protogen.exefor/f "delims="%%i in (' dir/b proto "Proto/*.proto" ') do%Path%-i:proto/%%i-o: Cs/%%~ni.cspause
"Protobuf Advanced" Export C # supported. CS class files through the. Proto file