protocol-buffers

Protobuf-net creating typemodel with interface and abstract baseclass

让人想犯罪 __ 提交于 2019-12-04 15:44:50
问题 I'm trying to serialize a model using the great Protobuf-NET. I cannot use the attributes (objects are unknown at compile-time),so I constructed a TypeModel. My object model consist of a class TestDataObject , this class has a property of ITestDataExtension . The abstract baseclass TestDataExtensionBase implements this interface and the class TestDataExtension (myDataObjectExtA in code) inherits from this baseclass. My TypeModel is constructed like this: System.IO.MemoryStream tmpMemoryStream

Getting all field names from a protocol buffer?

霸气de小男生 提交于 2019-12-04 15:34:13
问题 I want to get all the field names of a proto into a list. Is there a way to do this? I looked in the documentation and there doesn't seem to be anything for this. 回答1: Every proto class possess a DESCRIPTOR class variable that can be used to inspect the fields of corresponding protobuf messages. Have a look at the documentation of the Descriptor and FieldDescriptor classes for more details. Here is a simple example to get the FieldDescriptor s of all the fields in message into a list: res =

How to add a int array in protobuf message

人盡茶涼 提交于 2019-12-04 15:07:53
问题 I have to compose a protobuf message which should have 1 integer variables and a integer array. package protobuf; message myProto { optional uint32 message_id =1; optional int update = 2; //here I have to add a array of integers //can I write like optional int[] array =3; //or should I use optional repeated array; //where array is another message with int variable } Is my approach correct? Please help me Thanks 回答1: Array is mapped via "repeated": repeated int32 data = 4; Note you might want

Google Protocol Buffers or something similar for .net/javascript

你离开我真会死。 提交于 2019-12-04 13:47:46
问题 We are currently using Ajax calls to a .net web service that then returns a Json object to the client. Some of these Json objects are pretty massive (> 500k uncompressed). We have heard some good things about Google Protocol Buffers and have been experimenting. So far, we have had pretty good luck serializing on the server with what seems to be the most common .net version - "protobuf-net". We have not had much luck deserializing on the client. We tried using what seems to be the one and only

Using ProtoBuf-net with gRPC

霸气de小男生 提交于 2019-12-04 12:59:04
I am trying to build a PoC at work that utilizes gRPC. The google document here takes us through a sample application. I was wondering if protobuf-net, and specifically protogen, had the capability to understand service definitions and classes necessary to perform gRPC calls? Or is this something being worked on? Would it work if I use google's protoc for client and server code generation(which involves the service definitions and RPC calls) and protobuf-net for my business objects. protobuf-net.Grpc is now a thing... albeit in preview. When .NET Core 3 comes out, we should be able to make

Automate compilation of protobuf specs into python classes in setup.py

不想你离开。 提交于 2019-12-04 12:55:58
I have a python project that uses google protobufs as a message format for communicating over the network. Generating python files from the .proto files is straight-forward using the protoc program. How can I configure my setup.py file for the project so that it automatically calls the protoc command? In a similar situation, I ended up with this code (setup.py, but written in a way to allow extraction into some external Python module for reuse). Note that I took the generate_proto function and several ideas from the setup.py file of the protobuf source distribution. from __future__ import

Parsing a raw Protocol Buffer byte stream in C#

淺唱寂寞╮ 提交于 2019-12-04 12:38:39
Given a protocol buffer encoded Stream or byte[] but NOT knowing the object type itself, how can we print the skeleton of the message? The use case is for debugging IO that's protobuf based, for root cause analysis. If there are existing tools that can parse the raw Protocol Buffer byte stream from a binary file - that would be great! An alternative could be using the ProtoBuf.NET class ProtoReader() to keep chugging along till we hit the error but the usage of ProtoReader() isn't clear. I started as below but couldn't find good documentation on how to use the ProtoReader class to actually do

Cannot deserialize protobuf data from C++ in Java

我只是一个虾纸丫 提交于 2019-12-04 12:28:10
My problem is to serialize protobuf data in C++ and deserialize the data in Java probably. Here is the code I use to the hints given by dcn: With this I create the protobuf data in C++ and write it to an ostream which is send via socket. Name name; name.set_name("platzhirsch"); boost::asio::streambuf b; std::ostream os(&b); ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&os); CodedOutputStream *coded_output = new CodedOutputStream(raw_output); coded_output->WriteLittleEndian32(name.ByteSize()); name.SerializeToCodedStream(coded_output); socket.send(b); This is the Java side where I

Android protobuf nano usage

大兔子大兔子 提交于 2019-12-04 12:14:25
问题 I am trying to generate java files from below proto file using protobuf nano. I got some basic instruction on how to proceed in this SO thread. I have this proto file, personal.proto : package tutorial; option java_package = "com.example.tutorial"; option java_outer_classname = "AddressBookProtos"; message Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { required string number = 1;

Read value of enum extension in protocol buffer

百般思念 提交于 2019-12-04 11:20:37
I just asked this question and have resolved to write an extension for enum values in my protocol buffer. However I am having an extremely difficult time actually reading the values back, even with this simple .proto file: package test; import "google/protobuf/descriptor.proto"; extend google.protobuf.EnumValueOptions { optional string abbr = 54321; } message Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0 [(abbr)="Mobile ph"]; HOME = 1 [(abbr)="HomePhone"]; WORK = 2 [(abbr)="Work number"]; } message PhoneNumber { required string