我正在尝试使用Google protobuf,我正在进行下一个描述:
message.proto文件:
message Request {
required int32 id = 1;
optional string value = 2;
}
Run Code Online (Sandbox Code Playgroud)
service.proto文件:
import "message.proto";
service Service {
rpc request (Request) returns (bool);
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试生成c ++源代码并收到错误:
$ protoc service.proto --cpp_out =/tmp/proto/build
service.proto:4:40:预期的消息类型.
我是否必须仅返回用户定义的类型?是原始的(像bool或string)支持?我可以使用原始类型作为服务方法参数(而不是Request在我的示例中)吗?
我们的项目中有一个build.xml,但IntelliJ无法从中导入.我得到一个:
Cannot import anything from <path_to>/build.xml file.
Run Code Online (Sandbox Code Playgroud)
在Eclipse上我可以做一个:
File -> Import -> General -> Existing Projects into workspace.
Run Code Online (Sandbox Code Playgroud)
并选择了顶级文件夹.我也在IJ做过同样的事.项目导入和索引很好,我可以搜索任何类.但是,它无法识别protobuf编译的类文件.我安装了proto插件,因此它的语法突出显示了我的.proto文件,但仍然没有意识到它需要引用的编译类输出.我是否需要做一些特别的事情来让它识别这些文件?
如何根据 Google 协议缓冲区中的要求定义重复字段?我有一个修饰符重复的字段(repeated int32 A )。如何向该字段添加所需的修饰符?事实上我想要两个修饰符(必需和重复)。
当我根据以下内容在Mac上安装caffe时:
剩下的依赖关系,带/不带Python
# with Python pycaffe needs dependencies built from source
brew install --build-from-source --with-python -vd protobuf
brew install --build-from-source -vd boost boost-python
# without Python the usual installation suffices
brew install protobuf boost
Run Code Online (Sandbox Code Playgroud)
我将第二个粘贴到终端,结果是:
Error: invalid option: --with-python
Run Code Online (Sandbox Code Playgroud)
我找不到任何类似的问题,有什么可以帮助我的吗?
考虑以下消息。
message example {
repeated string text;
}
Run Code Online (Sandbox Code Playgroud)
假设在 C++ 中,我将一个字符串列表插入到示例的文本字段中:
exemple aMessage;
std::list<std::string> aList = ... ;
for (std::string anStr : aList)
{
aMessage.add_text(anStr);
}
Run Code Online (Sandbox Code Playgroud)
稍后,如果我访问我的消息文本,该字段的排序方式是否与我的列表相同?当我将它序列化并将其发送到某个地方时呢?
订单会保持不变吗?
我想将 int/int64/double/float/uint32/uint64 序列化为 protobuf,我应该使用哪一个?哪一种更有效?
例如 :
message Test {
google.protobuf.Any any = 1; // solution 1
google.protobuf.Value value = 2; // solution 2
};
message Test { // solution 3
oneof Data {
uint32 int_value = 1;
double double_value = 2;
bytes string_value = 3;
...
};
};
Run Code Online (Sandbox Code Playgroud) 我不知道如何在 protobuf-c 中表示指针。
当有如下结构时
struct EXAMPLE1
{
int32 x;
int32 *y;
};
Run Code Online (Sandbox Code Playgroud)
我如何在 protobuf-c 中表示指针变量(y)?
message EXAMPLE1
{
int32 x;
?? y;
}
Run Code Online (Sandbox Code Playgroud) 我有窗户。我想使用库 tensorflow 创建一个 C++ op。从这个网站https://www.tensorflow.org/guide/extend/op#compile_the_op_using_your_system_compiler_tensorflow_binary_installation我明白我应该做以下:
TF_CFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') )
TF_LFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))') )
g++ -std=c++11 -shared zero_out.cc -o zero_out.so -fPIC ${TF_CFLAGS[@]} ${TF_LFLAGS[@]} -O2
Run Code Online (Sandbox Code Playgroud)
我就是这么做的。但我遇到了下一个问题:
In file included from C:\Python\Python37\lib\site-packages\tensorflow\include/tensorflow/core/framework/op_def_builder.h:24,
from C:\Python\Python37\lib\site-packages\tensorflow\include/tensorflow/core/framework/op.h:23,
from zero_out.cc:4:
C:\Python\Python37\lib\site-packages\tensorflow\include/tensorflow/core/framework/op_def.pb.h:10:10: fatal error: google/protobuf/port_def.inc: No such file or directory
#include google/protobuf/port_def.inc
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Run Code Online (Sandbox Code Playgroud)
我不明白我该如何解决这个问题。如果你能帮我解决这个问题,我将不胜感激
我是使用 google protobuffers 的新手,我创建了一条基本消息:
message msg {
uint32 id = 1;
google.protobuf.Timestamp timestamp = 2;
}
Run Code Online (Sandbox Code Playgroud)
现在我创建了一个小型 C++ 程序来使用它[带有必要的标头]
int main(void) {
auto m = msg{};
m.set_id(2);
auto timestamp = google::protobuf::Timestamp{};
timestamp.set_seconds(time(NULL));
timestamp.set_nanos(0);
m.set_allocated_timestamp(×tamp);
std::cout << m.id() << std::endl;
std::cout << m.timestamp().seconds() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然而,这个程序给出了一个段错误。
free(): invalid pointer
[1] 9537 abort (core dumped)
Run Code Online (Sandbox Code Playgroud)
我需要在哪里释放内存?
protobuf-c ×10
c++ ×4
c ×1
caffe ×1
eclipse ×1
g++ ×1
python ×1
rpc ×1
tensorflow ×1
windows ×1