protocol-buffers

Is it possible to use Protobuf-Net with a class without a parameterless constructor?

巧了我就是萌 提交于 2019-12-23 07:48:43
问题 Using Protobuf-Net, I see that it does not seem possible to deserialize a class without having a parameterless constructor or I may be missing something? I don't want some of the classes with a parameterless constructor. Is there some kind of attributes that I could use or some other technique? 回答1: protobuf-net depends currently on having a parameterless constructor to work. However that constructor need not be public (it will use reflection if need be to invoke it) so you may be able to

How can I represent a 2-dimensional array in Protocol Buffers?

房东的猫 提交于 2019-12-23 07:38:09
问题 How can I represent a 2-dimensional array in Protocol Buffers? I need to store int and double 2d arrays as a field on a PB message, for example: int[][] multi = new int[5][10]; I'm using C++, Java and C#. Thanks in advance. 回答1: There is no direct support in the protocol for this. Your best bet is to have a repeated set of objects that have an array each - i.e. message Foo { repeated int items = 1; } ... repeated Foo foos = 1; 来源: https://stackoverflow.com/questions/20968626/how-can-i

Checking for valid enum types from protobufs

六眼飞鱼酱① 提交于 2019-12-23 03:51:51
问题 In my protobuf file called skill.proto, I have: message Cooking { enum VegeType { CAULIFLOWER = 0; CUCUMBER = 1; TOMATO = 2 } required VegeType type = 1; } In another file (eg: name.py) I want to check that the enum within the file is a valid type #if (myCookingStyle.type != skill_pb2.Cooking.VegeTypes): print "Error: invalid cooking type" How do I check that myCookingStyle.type is a valid enum type? ie: how do I do that commented line NB: I want to avoid doing hard coding of the checking for

No Member Found when use cmake construct proto

天大地大妈咪最大 提交于 2019-12-23 02:17:23
问题 I wish to use proto and managed by cmake. Suppose the files are as follow . ├── app1 │ ├── app1.cpp │ └── app1.proto ├── CMakeLists.txt ├── common │ ├── bar │ │ ├── bar.proto │ │ └── CMakeLists.txt │ └── foo │ ├── CMakeLists.txt │ └── foo.proto └── README.md If I wanna just generate some cpp files, I can just use command $ protoc --cpp_out=build common/bar/bar.proto $ protoc --cpp_out=build common/foo/foo.proto and the desired files can be generated. However, if I use CMake, it will report an

Protobuf doesn't serialize default values

不想你离开。 提交于 2019-12-22 17:44:24
问题 I'm using Protobuf for python. I've been trying to use default values but everytime I run SerializeToString() i get nothing. For example, here is my .proto file object message Test{ optional string lol = 1 [default="HI"]; optional int32 num = 2 [default=200]; } I run test = packets_pb2.Test() print(test.num) print(test.SerializeToString()) and get 200 for print(test.num) but no results (empty) for SerializeToString() I want my default values to be serialized. Any idea how to get this done?

Protocol Buffer: How to import?

故事扮演 提交于 2019-12-22 17:42:29
问题 I have 2 .proto files : First file: package com.test.model; message ProtoModel { required CustomObj custom=1; } Second file: package com.test.model; message CustomObj { required string smth=1; } The issue here is that "CustomObj" is said to be "unresolved reference" . Thus, I've tried to import the second file into first file: import "com/test/model/firstFile.proto" package com.test.model; message ProtoModel { required CustomObj custom=1; } I still get the same issue !! 回答1: The import

How to build google protobuf environment with cmake on windows?

ⅰ亾dé卋堺 提交于 2019-12-22 17:15:08
问题 I am following the instructions from: https://github.com/google/protobuf/tree/master/cmake cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../../../install/protobuf ../.. nmake install In my program's CMakeLists.txt i use: find_package(Protobuf REQUIRED) But it tells me: -- Could NOT find Protobuf (missing: Protobuf_LIBRARIES Protobuf_INCLUDE_DIR) I think I should set set the environment variable. Is there a effective way to do this? in protobuf-master/cmake

Why is a publicly visible Bazel ProtoBuf target 'not declared'

一个人想着一个人 提交于 2019-12-22 16:01:18
问题 I'm attempting to use Bazel's Protocol Buffer Rules to compile (generate) Python language bindings and any dependencies. The layout of my project is simple, with a single directory, proto , containing the .proto file and BUILD file. WORKSPACE BUILD.six |-- proto | |-- example.proto | |-- BUILD My WORKSPACE file: workspace(name = "com_example") http_archive( name = "com_google_protobuf", strip_prefix = "protobuf-3.4.1", urls = ["https://github.com/google/protobuf/archive/v3.4.1.zip"], ) new

How to send / receive binary data serialized with Protocol Buffers using ZMQ

断了今生、忘了曾经 提交于 2019-12-22 10:45:09
问题 I need to send an object (serialized with GPB) on a ZMQ socket. Currently the code have an extra copy. How do I directly write serialized array into message_t s data? ABT_CommunicationProtocol introPacket; // Fill the packet message_t introMessage; size_t dataLenght = introPacket.ByteSize(); char* temp = new char[dataLenght]; introPacket.SerializeToArray(temp, dataLenght); // write data to temp memcpy(introMessage.data(), temp, dataLenght); // copy data to message this->serverRquest.send

Serializing/Deserializing Protocol Buffers

半城伤御伤魂 提交于 2019-12-22 10:36:00
问题 I am currently working with Protocol Buffers (version 3 C#). I am sending messages back and forth to different services. and currently trying to save some data stored in certain messages to a database (could be of any kind really). The problem being that byte[] is created as the type ByteString and List< T> is created as RepeatedField< T> . Now the issue I have with these are that I haven't managed to serialize or deserialize them 100% successfully. Basic types works like a charm, but