This article is a mirror article of machine translation, please click here to jump to the original article.

View: 28320|Reply: 7

[Source] .net/c# Google Protocol Buffers Quick Start

[Copy link]
Posted on 4/11/2017 2:08:58 PM | | | |
Google Protocol Buffers is a protocol generation tool produced by Google, which is cross-platform, efficient, and fast, which is very helpful for our own program definition and use of private protocols.

I read many articles on the Internet, and I feel that they are all nonsense, reprinted by JX!!


They are all very old articles, and then copy and paste, and find that many people have a characteristic, and they feel that they are very advanced articles, so they like to copy and paste without practicing them!!



First: First, we prepare a .proto file, following Google's format message, the name of a class required field, I found a random file from the Internet, as follows:



Second: Download the package with nuget with the following command:



Third: Find the location of the package in your project folder, as follows:

C:\项目文件夹\packages\Google.ProtocolBuffers.2.4.1.555\tools
My location is: C:\project\MyProjects\Study\packages\Google.ProtocolBuffers.2.4.1.555\tools

Fourth: Copy the ProtoMyRequest.proto file to the tools folder and execute the following commands:

A CS file is then generated and copied to the project!!

Recompile, via! No errors! In the next lesson, let's talk about how to use it.








Previous:Make Linq's OrderBy support dynamic fields
Next:.net/c# SendCloud Mass Mail [Source Code]
Posted on 4/24/2017 2:27:44 PM |
package represents the package name where the file is located in Java, the namespace of the file in C#, message represents a class, required represents the field required, optional means the field is optional, and the default value can be set for it, the default value format of string is [defalut="string") The default value format of integer is [defalut=23333]
Here is the field type conversion table for protobuf in the .proto file:
 Landlord| Posted on 5/3/2017 1:33:39 PM |
.net/c# Google Protocol Buffers tutorial
http://www.itsvse.com/thread-3668-1-1.html
(Source: Architect)
Posted on 11/16/2017 3:41:01 PM |
Landlord, thank you for your hard work. I have a question to ask: protoc --descrip{filter}tor_set_out=ProtoMyRequest.protobin --include_imports ProtoMyRequest.proto
Where is this implemented, the whole process is not too clear, please advise. Thank you. You can contact me on QQ (512501372), because it is the first time to use this tool, if you are offended, please forgive me.
 Landlord| Posted on 10/29/2019 11:15:46 AM |

 Landlord| Posted on 8/31/2023 6:38:48 PM |
wangsea posted on 2017-11-16 15:41
Landlord, thank you for your hard work. I have a question to ask: protoc --descrip{filter}tor_set_out=ProtoMyRequest.protobin --include_ ...

Install the Google.ProtocolBuffers package under the packages\Google.ProtocolBuffers.2.4.1.555\tools directory.
 Landlord| Posted on 8/31/2023 6:52:55 PM |

Instead of creating a new .proto file, use protobuf-net for simple serialization and deserialization

The nuget reference command is as follows:

Create a new class and add features as follows:

Serialized and deserialized code:




Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com