如果我使用旧版本,Protobuf 会成功生成我的原型,但是当我将 protobuf 依赖项更新到最新的 1.34.1 时,我总是遇到这个问题。
如果我使用旧版本,Protobuf 会成功生成我的原型,但是当我将 protobuf 依赖项更新到最新的 1.34.1 时,我总是遇到这个问题。
错误
C:\Users\1\AndroidStudioProjects\capella-client-androidd\app\build\generated\source\proto\debug\javalite\api\AbonentOuterClass.java:337: error: an enum switch case label must be the unqualified name of an enumeration constant
case IS_INITIALIZED: {
^
C:\Users\1\AndroidStudioProjects\capella-client-androidd\app\build\generated\source\proto\debug\javalite\api\AbonentOuterClass.java:340: error: an enum switch case label must be the unqualified name of an enumeration constant
case MAKE_IMMUTABLE: {
^
C:\Users\1\AndroidStudioProjects\capella-client-androidd\app\build\generated\source\proto\debug\javalite\api\AbonentOuterClass.java:346: error: an enum switch case label must be the unqualified name of an enumeration constant
case VISIT: {
^
C:\Users\1\AndroidStudioProjects\capella-client-androidd\app\build\generated\source\proto\debug\javalite\api\AbonentOuterClass.java:347: error: cannot find symbol
Visitor visitor …Run Code Online (Sandbox Code Playgroud) 给定一个这样的原型:
message Request {
uint64 account_id = 1;
message Foo{
uint64 foo_id = 1;
}
repeated Foo foos = 2;
Run Code Online (Sandbox Code Playgroud)
当我添加一个名为的字段时bar_id
message Request {
uint64 account_id = 1;
message Foo{
uint64 foo_id = 1;
uint64 bar_id = 2;
}
repeated Foo foos = 2;
Run Code Online (Sandbox Code Playgroud)
client使用旧的via反序列化时出现错误proto.UnmarshalText(msg, request)。错误是unknown field name "bar_id" in serviceA.Request_Foo。
我知道 proto-3 中的处理方式发生了很多变化unknown field,但这不是预期的,因为它似乎违反了前向兼容性(新服务器向旧客户端发送请求)。这与使用嵌入类型有关吗?在不强制客户端更新的情况下更新服务器的最佳方法是什么?
我想为接受任何 google protocol buffer 对象的函数中的参数添加类型提示。
def do_something(protobuf_obj: WHAT_IS_HERE):
# protobuf_obj can be any protocol buffer instance
pass
Run Code Online (Sandbox Code Playgroud)
我应该从图书馆放什么课google.protobuf?
在编译原型文件时,我收到““int”未定义”。
“测试.proto”文件
syntax = "proto3";
package test;
option go_package = "/;test";
message User {
string FirstName = 1;
string LastName = 2;
string Address = 3;
int Contact = 4;
int Age = 5;
}
Run Code Online (Sandbox Code Playgroud)
Output:
test.proto:11:5: "int" is not defined.
Run Code Online (Sandbox Code Playgroud) 我想在 google cloud pub/sub 控制台中创建这个 protobuf 架构。
我有一个本地脚本,我在其中使用 protobuf 成功序列化和反序列化数据。
syntax = "proto2";
package mypackage;
message VideoImpression {
optional string user_id = 1;
optional string candidate_id = 2;
optional int64 event_timestamp = 3;
}
message VideoImpressionsList {
repeated VideoImpression video_impressions = 1;
}
Run Code Online (Sandbox Code Playgroud)
当我保存架构时,出现此错误:
Too many message types specified in schema definition.
我尝试将两条消息拆分为单独的模式定义,但随后它会抱怨,例如在保存消息 VideoImpressionsList 时:
"VideoImpression" is not defined.
如何使 pub/sub 接受上面定义的两种消息类型的模式?
谢谢你的帮助
schema protocol-buffers google-cloud-platform google-cloud-pubsub
我目前有两个 protobuf 存储库:api 和timestamp:
时间戳回购:
- README.md
- timestamp.proto
- timestamp.pb.go
- go.mod
- go.sum
Run Code Online (Sandbox Code Playgroud)
API 仓库:
- README.md
- protos/
- dto1.proto
- dto2.proto
Run Code Online (Sandbox Code Playgroud)
目前,timestamp包含对我想要使用的时间戳对象的引用,api但我不确定导入应该如何工作,或者我应该如何修改编译过程来处理这个问题。让这个过程变得复杂的是,该api存储库被编译为 Go 的一个单独的下游存储库,名为api-go.
例如,考虑dto1.proto:
syntax = "proto3";
package api.data;
import "<WHAT GOES HERE?>";
option go_package = "github.com/my-user/api/data"; // golang
message DTO1 {
string id = 1;
Timestamp timestamp = 2;
}
Run Code Online (Sandbox Code Playgroud)
我的编译命令是这样的:
find $GEN_PROTO_DIR -type f -name "*.proto" -exec protoc \
--go_out=$GEN_OUT_DIR …Run Code Online (Sandbox Code Playgroud) “protobuf 需要 Python '>=3.7' 但运行的 Python 是 3.6.4”
亲爱的社区,我正在使用 CARLA 模拟器,为此我需要使用 python 3.6 和 protobuf。当我想安装“protobuf”时,出现此错误“protobuf 需要 Python '>=3.7' 但正在运行的 Python 是 3.6.4” 有人知道该怎么办吗?
我正在编写一个使用protobuf作为序列化系统的轻量级服务器-客户端系统。我在protobufs抱怨缺少必填字段时遇到问题,但是1)字段显然在数据流中; 2)错误消息无法识别出缺少的字段。
首先一点代码:
myMessages::DataRequest cData; // this is declared outside of the function in the global
// so it can be reused each time to avoid unnecessary
// memory allocation. Per the documentation in protobufs
.
.
.
bool processStream(u_int8_t *pStream, u_int32_t dwLength)
{
try
{
if (!cData.ParseFromArray(pStream, dwLength))
{
printf("Failed to parse data stream\n");
hexdump(pStream, dwLength);
return false;
}
}
catch(exception e)
{
printf("Exception in ParseFromArray: %s", e.what());
hexdump(pStream, dwLength);
return false;
}
Run Code Online (Sandbox Code Playgroud)
这是我获取完整数据流并尝试让protobufs对其进行解码的代码。在大多数情况下,这可以正常工作。但是通过此代码进行的如此多次迭代都会出现此错误:
[libprotobuf ERROR google/protobuf/message_lite.cc:123] Can't parse …Run Code Online (Sandbox Code Playgroud) 我有一个文件"test.txt"包含testMessage.writeDelimitedTo(the-DataOutputStream-that uses a new FileOutputStream pointing to the file)每行写的多个protobuf"TestMessage"消息.如何阅读每行test.txt并获取每行的protobuf?
使用包含字符串的文件上的bufferedreader,我会这样做:
String strLine; // What is the alternative to String?
while ((strLine = br.readLine()) != null) {
System.out.println (strLine);
TestMessage test = new TestMessage.builder();
test.parseDelimitedFrom(strLine);
}
Run Code Online (Sandbox Code Playgroud)
如果我要使用此方法,我应该将类型设置为"String"而不是"String"?这可能吗?
或者我可以不这样做,每个mressage必须写入一个单独的文件?
注意:假设TestMessage是唯一的消息.
我正好有这个问题:
在张量流服务模型上运行预测后,我得到了这个PredictResponse对象作为输出:
outputs {
key: "scores"
value {
dtype: DT_FLOAT
tensor_shape {
dim {
size: 1
}
dim {
size: 2
}
}
float_val: 0.407728463411
float_val: 0.592271506786
}
}
Run Code Online (Sandbox Code Playgroud)
如该问题的建议,我尝试使用:result.outputs ['outputs']。float_val
但是它返回类型 <type google.protobuf.pyext._message.RepeatedScalarContainer>
它是由这段代码产生的,灵感来自inception_client.py示例:
channel = implementations.insecure_channel(host, int(port))
stub = prediction_service_pb2.beta_create_PredictionService_stub(channel)
result = stub.Predict(request, 10.0) # 10 secs timeout
Run Code Online (Sandbox Code Playgroud)
提前致谢!
protocol-buffers ×10
go ×3
python ×3
c ×1
c++ ×1
carla ×1
github ×1
grpc ×1
java ×1
proto ×1
proto3 ×1
protobuf-c ×1
protobuf-go ×1
schema ×1
tensorflow ×1
type-hinting ×1