proto file contains fields beginning with an underscore

322 views
Skip to first unread message

wulun00

unread,
Aug 11, 2022, 9:15:28 AM8/11/22
to Protocol Buffers
I tried to convert a proto file that contains fields beginning with underscores to a c# file, but it cannot be converted to the correct CS file
example:
msg.proto
syntax = "proto2";
message Msg {
  optional string _400Url = 1;
}

Msg.cs 
/// <summary>Field number for the "_400Url" field.</summary>
public const int 400UrlFieldNumber = 1;
private readonly static string 400UrlDefaultValue = "";

private string 400Url_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string 400Url {
get { return 400Url_ ?? 400UrlDefaultValue; }
set {
400Url_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}

Unable to compile because of 400Url

Jon Skeet

unread,
Aug 12, 2022, 9:32:55 AM8/12/22
to Protocol Buffers
This looks like issue 8101, which was fixed very recently (PR 10268).  Unfortunately I don't believe it's been included in a release yet, but you could fetch the latest code to build a version of protoc with the fix, or temporarily manually patch the generated code to add an underscore (so _400Url and _400Url_).
Reply all
Reply to author
Forward
0 new messages