【发布时间】:2013-07-24 14:31:46
【问题描述】:
我刚刚开始使用 Google Protocol Buffers 和 Marc Gravell 令人敬畏的 protobuf-net 程序,我不明白的一件事是生成的 .proto 文件中字段声明的命名约定。
以下是 Google 的建议:
“使用 underscore_separated_names 作为字段名称——例如,song_name。” https://developers.google.com/protocol-buffers/docs/style
“请注意,方法名称始终使用驼峰式命名,即使 .proto 文件中的字段名称使用带下划线的小写(应该如此)。” https://developers.google.com/protocol-buffers/docs/reference/java-generated
“请注意这些访问器方法如何使用驼峰式命名,即使 .proto 文件使用带下划线的小写字母。” https://developers.google.com/protocol-buffers/docs/javatutorial
但是当我在 protobuf-net 中使用 Serializer.GetProto() 方法时:
[ProtoContract]
public partial class AuthEntry
{
private string _windowsAccount = "";
private string _machineNames = "*";
[ProtoMember(1)]
public string WindowsAccount
{
get { return _windowsAccount; }
set { _windowsAccount = value; }
}
[ProtoMember(2)]
public string MachineNames
{
get { return _machineNames; }
set { _machineNames = value; }
}
}
我明白了:
message AuthEntry {
optional string WindowsAccount = 1;
optional string MachineNames = 2;
}
而不是像我预期的那样:
message AuthEntry {
optional string windows_account = 1;
optional string machine_names = 2;
}
我猜这没什么大不了的,但以防万一......
【问题讨论】:
-
我们使用 protoc 将 Protocol Buffers 编译成 JavaScript,这很烦人,因为 PascalCase 属性编译成“getLowercase”getter 和 setter,例如。获取 Windows 帐户,获取机器名称。它很难阅读,我们不能使用代码拼写检查。
标签: protocol-buffers protobuf-net