2013-07-24 38 views
1

我刚刚开始使用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; 
} 

我猜这是没有什么大不了的,但以防万一...

回答

1

原生代不会尝试应用这些约定,因为这样它就会进入消除歧义,碰撞等军备竞赛 - 没有提到在CustomerIDReference这样的任意名称中寻找单词分隔符的乐趣(好吧,那是一个不太可能的例子,但你明白了)。如果你想自己控制它 - 在ProtoContractAttribute或ProtoMemberAttribute上指定Name属性。