(ii) C # use of Protobuf

Source: Internet
Author: User
Tags format message

"Turn" http://blog.csdn.net/shantsc/article/details/50729402

Protobuf C # version is divided into two versions, one is protobuf-net and the other is Protobuf-csharp-sport

One, protobuf-net version

Step 1. Edit 111.proto file Follow Google format message A class name required must be assigned a field

1 Message Person2 {  3RequiredstringName=1;4Required Int32 id=2;5OptionalstringEmail=3;6 7     enumPhonetype8     {9monile=0;TenHome=1; Onework=2; A     } -}

Step 2. Compile the protobuf-net and then compile the references in the Protogen Protogen.exe
Step 3: Under DOS CD to Protogen.exe then-i:111.proto-o:111.cs-ns:myproto

Below is another version of the

Second, protobuf-csharp-sport version

The steps are as follows:

1. Download the Protobuf-csharp-port package from the http://code.google.com/p/protobuf-csharp-port/website first, The version I downloaded is: protobuf-csharp-port-2.4.1.473-release-binaries.

2. After extracting the above package, remove the Protogen.exe.config,protoc.exe,protogen.exe and Google.ProtocolBuffers.dll files into the D:\protoc folder.

(The D:\protoc folder is self-built).

3. Open the command prompt (my windows7 system), first use the CD C: \ command in the doc command to go to the B-drive, and then enter D-Carriage, go to D-Drive, and then CD Protoc go to the D:\protoc folder. (very meticulous ha, even a bit verbose ha, but I have to use Google for every time ~)

4. Add the Protobuf files that need to be converted to C # into the D:\protoc folder, for example, we want to transfer addressbook.proto files.

5. At the command prompt, enter:

Protoc--descriptor_set_out=addressbook.protobin--include_imports Addressbook.proto

(After the above command, you will find a Addressbook.protobin file in the D Protoc folder)

Next:

Protogen Addressbook.protobin Enter

After the above command, the D disk Protoc folder more than a AddressBook.cs file, yes, this is the most attention to the ultimate goal file.

It's done, oh, it's simple.

6. Import the CS file into the project and you can use the ~

(ii) C # use of Protobuf

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.