Case insensitive languages and field names

70 views
Skip to first unread message

Carl Gay

unread,
Nov 4, 2023, 11:49:41 PM11/4/23
to Protocol Buffers
Hi. I'm implementing protocol buffers for a case-insensitive language (Dylan) and I'm wondering if there's prior art that would give me an idea how to handle the following case:

message M {
  string S = 1;
  oneof O {
    string s = 2;
  }
}

Since fields M.S and M.s are siblings, the names to access those fields will collide. I can generate the name "s*" for lowercase "s". Since "*" is invalid in proto field names that's future proof.

So I think I have a way forward but I'm curious if anyone knows of other languages that have already addressed this, and what they did.

The Common Lisp implementation ignores the problem and relies on it not happening.  The docs for the PHP implementation don't mention this particular problem. (They do mention reserved names such as Empty being renamed to PBEmpty, but that's not a problem for Dylan.)

Thoughts?  Prayers?

Thanks.
-Carl

Carl Gay

unread,
Nov 5, 2023, 1:25:00 AM11/5/23
to Protocol Buffers
A couple more thoughts:

Auto-assigning a different name for the field, such as "s*", would have to be resilient to movement of the fields textually within the file. If the oneof were moved textually above field S the name "s*" could suddenly name a different field.

Another possibility: a custom field option: dylan_name = "s*". This assumes access to modify the .proto file, or the need to maintain a copy of it.

Maintain a custom name mapping file to pass to the proto parser / code generator.

(This is largely an academic exercise. This scenario seems unlikely to happen in practice, especially considering the number of Dylan users on the planet.)

sh...@google.com

unread,
Nov 21, 2023, 1:48:01 PM11/21/23
to Protocol Buffers
This is new to me as well. For Java it seems like it discerns the field by adding "_{field#}" to the end of accessor name. for example getS1(), getS2(). In C++, which I'm less familiar with, inserts the scope "O" between two fields, but keeps the same name i.e. "s". 
Reply all
Reply to author
Forward
0 new messages