RenniePet
RenniePet

Reputation: 11658

Incorrect naming convention for fields in .proto files generated by protobuf-net?

I'm just getting started with Google Protocol Buffers and Marc Gravell's awesome protobuf-net program, and one thing I don't understand is the naming convention for the field declarations in a generated .proto file.

Here's what Google is recommending:

"Use underscore_separated_names for field names – for example, song_name." https://developers.google.com/protocol-buffers/docs/style

"Note that method names always use camel-case naming, even if the field name in the .proto file uses lower-case with underscores (as it should)." https://developers.google.com/protocol-buffers/docs/reference/java-generated

"Notice how these accessor methods use camel-case naming, even though the .proto file uses lowercase-with-underscores." https://developers.google.com/protocol-buffers/docs/javatutorial

But when I use the Serializer.GetProto() method in protobuf-net on this:

  [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; }
     }
  }

I get this:

message AuthEntry {
   optional string WindowsAccount = 1;
   optional string MachineNames = 2;
}

Instead of this, as I'd expected:

message AuthEntry {
   optional string windows_account = 1;
   optional string machine_names = 2;
}

I'm guessing it's no big deal, but just in case ...

Upvotes: 2

Views: 6091

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062915

The proto generation doesn't attempt to apply those conventions, because then it gets into the arms race of disambiguation, collisions, etc - no to mention the fun of finding word breaks in arbitrary names like CustomerIDReference (ok, that's an unlikely example, but you get the point). If you want to control that yourself - specify the Name property on either ProtoContractAttribute or ProtoMemberAttribute.

Upvotes: 1

Related Questions