course protobuf-net offers many kinds of high-level language support. As we do in unity we use the C # language, which requires two tools, one is protobuf-2.5.0 protoc.exe convert. Proto files to "Filedescriptorset" intermediate format The other is to use the Protogen.exein protobuf-net to convert the intermediate format file to the final state, the parsing class . cs file for the high-level language.
Can be downloaded to GitHub protobuf-net Source: protobuf-net, download and unzip to the
at run time, while iOS is AOT (full) compilation, so any library that is JIT -only will not work on iOS .To learn about the JIT and the AOT, see the following URLs :Jit:http://en.wikipedia.org/wiki/just-in-time_compilationAot:http://en.wikipedia.org/wiki/aot_compilerHttp://www.mono-project.com/AOTAfter an attempt, you can use protobuf-net precompilation to run on iOS and Android devicesNext, follow the steps, and finally attach the test project.First, download protobuf-net and configurationGo
download protobuf-net, of course, I was using the r668 version, there is nothing new I also did not check. Okay, no nonsense, now it's time to get to the chase.FirstDownload Protobuf-net, unzip to the directory you want, according to the original meaning to put two Precompile\precompile.exe and protogen\protogen.exe Two files are added to the environment variable and are then easy to use. The first time I used the environment variable set but do not
applications.
Protobuf-Net
Official site:Http://code.google.com/p/protobuf-net/
Protobuf-net is one of the most powerful and widely used third-party systems. It supports. net, C #, WCF, and VB, and has a wide range of demos. It can also find the most information on the Internet.
Generate a. CS File
After installation, use protogen.exe to generate the. CS file from the. proto file (in the demo, I encapsulate the command in/tools/getcs. BAT ):
Echo on
Java server and C # Client communication technology research background and purpose:ARPG Project requirements: You need to change your existing server from the authoring platform of C + + to the Java language.In the process of analyzing the requirements, we find some problems that need to be researched and realized.
Java and c+ language characteristics are very different, compared to the c+ and C # relationship, Java needs some C # style data structure and encoding format compatible;
class file we wantRequest.cs file contents are as followsView CodeBut 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 batchecho 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%
Protoc--descriptor_set_out=test.protobin--include_imports Test.proto will be reborn as a Test.protobin file under the folderThen run Protogen test.protobin to generate the Test.cs file.The CS file can then be added directly to the project using theAs an example:Create a new WebService projectAdd method[WebMethod] Public byte [] Test () { returnnew Person.builder (). SetId (1). SetName (" Wang Nima "). Setemail ("[email prot
"Turn" http://blog.csdn.net/shantsc/article/details/50729402Protobuf C # version is divided into two versions, one is protobuf-net and the other is Protobuf-csharp-sportOne, protobuf-net versionStep 1. Edit 111.proto file Follow Google format message A class name required must be assigned a field1 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 comp
files can be deleted or backed up.or open the command line, located in the corresponding directory, you put proto file in the directory.Input: Protoc--descriptor_set_out=msg.protobin--include_imports Msg.protoMsg.protobin is the Prtobobin file to generate, you can use this bin file to generate CS filesThen enter Protogen msg.protobin use the bin file to generate CS files, so you can get the CSharp version of the Msg.cs file, while using the VS inside
output file path and file name
//-ns: Specify the source namespace, if not set the default is Proto file name namespace
// If there is a package XXX parameter in the proto file, the mandatory namespace name is xxx
protobuf-net\protogen\protogen.exe-i:demo.proto-o:pbmessage\ Pbmessage.cs-ns:pbmessage
Source file generation DLL Dynamic link library
The basic commands are:
c:\windows\microsoft.net\framework\v4.0.30319\csc.exe/noconfig/nowarn:1701,1702/n
# source codeThe second Google.ProtocolBuffers.dll is used to reference in a project.3, in the source code attached to a proto file, is based on the C # version of the specially modified, you can take out to do the build test, execute the following command can get C # source file:Protoc--descriptor_set_out=addressbook.protobin--proto_path=protos--include_imports protos\tutorial\ Addressbook.protoProtogen Addressbook.protobinIf you want to generate C # source code, you need to do a first step to
number commandExample 1:@echo offIf%1 = = 1 echo "a = 1"Example 2:Detect if a file exists@echo offIf Existe:1.txt echo "exist 1.txt"Goto Jump Execution Instructions@echo offNET userIf%errorlevel% = = 0 Goto successedif%errorlevel% = = 1 goto failed: successedecho Netuser executed successfully!Goto return: FailedEcho Netuser failed to execute!: Return Set Set commandFor parameter percent variable name in (related file or command) do commandParameters: For has 4 parameters/d/l/r/fExample:Set
/b/a "*.proto" ') do Protogen-i:%%i-o:%%~ni.csPauseUse Protoc.exe to generate a. cpp file from the command line using the. proto file that you define yourself.Using the Protobuf-net Protogen.exe to generate a. cs file, you can write a batch that reads as follows:Protoc-i=. --cpp_out=. Net.proto//In the current directory, the CPP is compiled Net.protoProtogen-i:net.proto-o:net.cs//In the current directory, generate Net.cs with Net.protoIn fact, the two
The socket of unity explorer transmits protobuf byte streams (1) and unityprotobuf
Recently, I am working on a card and board game project. I need to use socket to transmit protobuf byte streams. After searching for some blogs and articles on the internet, I found that it is not comprehensive, so I will share all the source code I have studied with you, because at the beginning, there may be some shortcomings. Thank you for making a brick ~~
This article mainly refers to the serialization and pa
. Other files can be deleted or backed up. (2) Open command line cmd, locate in the corresponding directory. Input: Protoc--descriptor_set_out=msg.protobin--include_imports Msg.proto msg.protobin is the Prtobobin file to be generated, you can make Use this bin file to generate CS file and then input Protogen msg.protobin Use the bin file to generate CS file, so you can get the Msg.cs csharp version of the file, while in VS use to introduce G
; - //reads the contents of a stream into a binary array -Ms. Read (Bytes,0, Bytes. Length); + returnbytes; - } + Catch(Exception e) A { atDebug.Log ("Serialization failed:"+e.tostring ()); - return NULL; - } -}Each message in the Protobuf file passes through the Protogen tool provided by protocol buffer, which can be turned into a class in C #, for examplemessage Test { string1; string 2 ;}After the transformat
Google.ProtocolBuffers.dll is used to reference in the project.
3, in the source code with a proto file, is based on the C # version specifically modified, you can take out to do the build test, execute the following command can get C # source files:
Protoc--descriptor_set_out=addressbook.protobin--proto_path=protos--include_imports protos\tutorial\ Addressbook.protoProtogen Addressbook.protobin
If you want to generate C # source code, you need to do the first step to compile the source file
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.