protobuf-net生成的.proto文件中字段的命名约定不正确



我刚刚开始使用Google Protocol Buffers和Marc Gravell令人敬畏的protobuf net程序,有一件事我不明白,那就是生成的.proto文件中字段声明的命名约定。

以下是谷歌的建议:

字段名称使用undercore_separated_name,例如song_namehttps://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;
}

我想这没什么大不了的,但以防万一。。。

原型生成不试图应用这些约定,因为这样它就进入了消除歧义、冲突等的军备竞赛,更不用说在CustomerIDReference等任意名称中查找分词的乐趣了(好吧,这是一个不太可能的例子,但你明白了)。如果您想自己控制它,请在ProtocoContractAttribute或ProtoMemberAttribute上指定Name属性。

最新更新