我剛剛開始使用Google協議緩衝區和Marc Gravell的awesome protobuf-net程序,但我不明白的是生成的.proto文件中字段聲明的命名約定。protobuf-net生成的.proto文件中字段的命名規則不正確?
下面是谷歌的建議:「使用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網的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;
}
我猜這是沒有什麼大不了的,但以防萬一...