-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect duplicate name error with extensions #161
Comments
message Derived1 {
message Base {
extensions 100 to max;
optional Derived1 derived = 101;
}
optional string foo = 1;
}
... Edit: Looked through the documentation. At the moment, nested extensions are processed just as if they were declared on the top level. There is no mechanism like |
Any word on this? I just started a project and imported 100+ .proto files that all reuse the same name with extensions that protobuf is currently bombing on. If someone could point me in the right direction, I could take a crack at it myself. |
At the moment, there is no facility like setExtension like in the official library. I've started to work on this but it's still a quite long road, requiring breaking API changes eventually. |
I admit to being very new at protobufs so I'm not sure how to continue your work. Do you have any sort of API in mind? Maybe I could start with submitting some unit tests? |
Got an idea. Let's say we have a proto like this: message A {
required string id = 1;
}
extend A {
optional string id = 2; // fqn: .id
}
message B {
extend A {
optional string id = 3; // fqn: .B.id
}
...
} Considering nesting like this, the API could look like: var A = builder.build("A");
var a = new A();
a.set("id", 123);
a.set(".id", 234); // using the fully qualified name of the extended field as the key
a.set(".B.id", 345); // using the fqn as well What do you think? |
Given your proto schema...do you envision be able to do something like... var A = builder.build('A');
var B = builder.build('B');
a.set({ // optionally allow for set using an object literal
'id': 123,
'.id': 234
});
b.set('id', 345);
a.set('.B', b); |
You can use an object to construct a message already. This internally uses Message#set, so with an extension mechanism like the proposed, it would be: var A = builder.build("A");
var a = new A({ 'id': 123, '.id': 234 }); |
I've implemented this with 3.5.0. Extended fields now use their fully qualified name as the field's name. There are no setters for extended fields, so the recommended way of setting them is: message A {
required string id = 1;
}
extend A {
optional string id = 2; // fqn: .id
}
message B {
extend A {
optional string id = 3; // fqn: .B.id
}
...
} var A = builder.build("A");
var a = new A();
a.set(".id", 234); // or a['.id'] = 234;
a.set(".B.id", 345); // or a['.B.id'] = 345;
... Please let me know if it is working for you. |
Works great; thanks! |
Here's a test case:
Derived1.derived
andDerived2.derived
should not clash, as they're in different messages. ProtoBuf.js incorrectly believesderived
should be a field ofBase
and thinks I've declared it twice:The text was updated successfully, but these errors were encountered: