Protocol Buffers can be installed via Nuget,
 PM> Install-Package Google.ProtocolBuffers  
Tools
As well as installing the protocol buffers library this will also download the tools required to compile .proto files and generate C# files from them. The tools will be located where the nuget package was installed to.
.proto
A .proto file will be required to generate the required files for usage. This example .proto defines a message called TestMessage with 3 properties. The package is used like a namespace and will also be used to generate the namespace of the classes in C#.
 syntax = "proto2";  
   
 package test_proto;  
   
 message TestMessage  
 {  
   required int32 Id = 1;  
   required string Name = 2;  
   optional string Details = 3;  
 }  
Protoc
To compile a .proto file locate protoc.exe in the tools dir and run it with the following parameters.
 protoc -oitem test.proto  
ProtoGen
The next step is to generate the .cs files that will contain the generated code that can be used to create and serialize the data.
 .\ProtoGen.exe item  
Serialization
 var builder = new TestMessage.Builder();  
   
 builder.Id = 2;  
 builder.Name = "Test";  
 builder.Details = "Some Detials";  
   
 var message = builder.Build();  
   
 var bytes = message.ToByteArray();  
Deserialization
 var builder = new TestMessage.Builder();  
 builder.MergeFrom(bytes);  
 var message = builder.Build();  
Other Methods
message.ToJson() & message.ToXml()
These can be used to visualize the message in other formats.
message.WriteTo(Stream stream)
This is used to write the bytes to a stream.
References
https://developers.google.com/protocol-buffers/
https://developers.google.com/protocol-buffers/docs/reference/proto2-spec
https://github.com/google/protobuf
 
How do I use this with Google transit? WHat is the process
ReplyDeleteC# that is
ReplyDeleteGood content. You write beautiful things.
ReplyDeletesportsbet
korsan taksi
mrbahis
hacklink
vbet
hacklink
taksi
vbet
sportsbet
Minor misspelling in the first sentence: "does not use relection" should be "does not use reflection". Cheers
ReplyDeletegüngören
ReplyDeleteeskişehir
esenyurt
trabzon
kadıköy
İBQ
https://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
R64ERV
Thankss for this blog post
ReplyDeleteYour tthe best
ReplyDelete