C # Use the google protocolbuffer protocol,

Source: Internet
Author: User

C # Use the google protocolbuffer protocol,

Introduction

Google protocolbuffer, google provides three languages: java, c ++, and python, each of which contains the compiler and library files of the corresponding language. Because it is a binary format, it is much faster than using xml for data exchange.

It can be used for data communication between distributed applications or data exchange in heterogeneous environments. As a binary data transmission format with excellent efficiency and compatibility, it can be used in many fields such as network transmission, configuration file, and data storage.

The following describes how C # uses protocolbuffer.

 

Download protobuf-csharp-port-2.4.1.521-release-binaries.zip

Http://code.google.com/p/protobuf-csharp-port/

 

Proto File

// Import "Base. proto"; add reference file Method

Message LoginReq
{
Required int32 Result = 1; // 0: failed, 1: Successful
Optional bytes Cause = 2;
Optional bytes guid = 4; // unique ID request, optional
}

 

Required

Optional Option

Repeated list item

 

 

 

ProtocolGenerate

Put protoc.exe‑protogen.exe and Google. ProtocolBuffers. dll files in the downloaded file into the same folder as bat files and proto files.

Generate protocol bat file format:

 

@ Echo on
Protoc -- descriptor_set_out = LoginReq. protobin -- include_imports LoginReq. proto
Protogen LoginReq. protobin

 

LoginReq. cs is generated in this file.

 

The time is urgent and will be edited later.

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.