如何使用"grpc-web_out"命令保留"camelCase"的原型消息字段?还有其他选项吗?



我通过用";grpc-web_out";命令这些myptoto_pb.js文件包含flatcase中的所有proto消息字段(不区分大小写(。这里还有我遗漏的其他选项吗?如何使用区分大小写的camelCase字段生成js文件?(消息字段应保持原样(

我使用了以下命令来生成这些文件:

protoc.exe -I../grpc/proto/ --js_out=import_style=commonjs,binary:../src/grpchandlers/ ../proto/*.proto 
protoc.exe -I../grpc/proto/ --grpc-web_out=import_style=commonjs,mode=grpcwebtext:../src/grpchandlers/ ../grpc/proto/*.proto

这是的原型文件示例

//myproto.proto
syntax = "proto3";
option java_multiple_files = true;
option java_package = "com.grpc.messages";
option java_outer_classname = "CommonOuter";
option java_generic_services = true;
package remote;
import "base.proto";
message UserProfileInfo {
int64 userId = 1;
string userEmail = 2;
int64 companyDepartmentId = 3;
}
message UserProfileInfoArray {
repeated UserProfileInfo value = 1;
}

并生成JavaScript代码:

//myproto_pb.js
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Deprecated. Whether to include
*     the JSPB instance for transitional soy proto support:
*     http://goto/soy-param-migration
* @param {!proto.remote.UserProfileInfo} msg The msg instance to transform.
* @return {!Object}
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.remote.UserProfileInfo.toObject = function(includeInstance, msg) {
var f, obj = {
userid: jspb.Message.getFieldWithDefault(msg, 1, 0),
useremail: jspb.Message.getFieldWithDefault(msg, 2, ""),
companydepartmentid: jspb.Message.getFieldWithDefault(msg, 3, 0)
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};

这里,proto中的userId被转换为js代码中的userid。其他字段(userEmail、companyDepartmentId(也是如此。生成的JavaScript代码对于所有字段都应该具有类似的camelCase格式。

您应该使用snake_case来命名字段。

然后它将与camelCase一起生成。

参考:https://developers.google.com/protocol-buffers/docs/style#message_and_field_names