-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protoc.exe编译proto文件失败 #1
Comments
1、“属性赋值时,属性名不能自动带出,也不能访问”是指没有代码提示吗,确实没有,不过能根据属性点进去。 |
proto.SearchService.SearchSort.toObject = function(e, t) {
var a = {
field: r.Message.getFieldWithDefault(t, 1, ""),
order: r.Message.getFieldWithDefault(t, 2, 0)
};
return e && (a.$jspbMessageInstance = t),
a
}
),
proto.SearchService.SearchSort.serializeBinaryToWriter = function(e, t) {
var a = void 0;
a = e.getField(),
a.length > 0 && t.writeString(1, a),
a = e.getOrder(),
0 !== a && t.writeEnum(2, a)
}
proto.SearchService.SearchSort.deserializeBinary = function(e) {
var t = new r.BinaryReader(e)
, a = new proto.SearchService.SearchSort;
return proto.SearchService.SearchSort.deserializeBinaryFromReader(a, t)
}
,
proto.SearchService.SearchSort.deserializeBinaryFromReader = function(e, t) {
while (t.nextField()) {
if (t.isEndGroup())
break;
var a = t.getFieldNumber();
switch (a) {
case 1:
var r = t.readString();
e.setField(r);
break;
case 2:
r = t.readEnum();
e.setOrder(r);
break;
default:
t.skipField();
break
}
}
return e
}
,
proto.SearchService.SearchSort.prototype.serializeBinary = function() {
var e = new r.BinaryWriter;
return proto.SearchService.SearchSort.serializeBinaryToWriter(this, e),
e.getResultBuffer()
} 在python代码中,我是如下方式定义以及赋值的: # ①定义如下
syntax = 'proto3';
message SearchService {
message SearchSort {
string field = 1;
int32 order = 2;
}
message CommonRequest {
string searchType = 1;
string searchWord = 2;
SearchSort searchSort = 3;
#其他属性省略……
}
message SearchRequest {
CommonRequest commonRequest = 1;
int32 interfaceType = 2;
}
}
# ②赋值逻辑
import request_pb2 as pb
search_request = pb.SearchService.SearchRequest()
#SearchSort赋值
search_sort = pb.SearchService.SearchSort()
search_sort.field = ""
search_sort.order = 1
search_request.commonRequest.searchType = "paper"
search_request.commonRequest.searchWord = "哔站"
#SearchSort赋值
search_request.commonRequest.searchSort = search_sort
bytes_body = search_request.SerializeToString()
print(bytes_body)
|
pycharm专业版,没用插件。 search_request = pb.SearchService.CommonRequest() |
玺哥,在编写protobuf协议的demo时遇到了如下3个问题,麻烦有时间指导下,感谢!
①编译之后给属性赋值时,属性名不能自动带出,也不能访问,所以即使拼写错误,在代码运行前是无法发现的;
②如果属性是个对象如何赋值?(比如代码中的searchSort)
③在我升级了protoc.exe之后(3.21版本),再编译proto文件,结果只编译出了一半的内容,结果如下图,这是什么原因?
The text was updated successfully, but these errors were encountered: