-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
protobuf.js version: 6.8.7 (master e8449c4)
When calling protobuf.Root.fromJSON
on a JSON descriptor of a proto that contains an extend
, an error is thrown saying the extended field is a duplicate.
For example a proto like:
syntax = "proto3";
package mypackage.options;
import "google/protobuf/descriptor.proto";
enum Scope {
ALL = 0;
HINT = 1;
}
extend google.protobuf.FieldOptions {
repeated Scope scope = 12345;
}
And the following in TypeScript:
import * as protobuf from 'protobufjs/light';
import * as Long from 'long';
protobuf.util.Long = Long;
protobuf.configure();
import * as protoDescriptor from './proto-reflection';
import {INamespace} from 'protobufjs';
export const protoRoot = protobuf.Root.fromJSON(protoDescriptor as INamespace);
Results in the error:
type.js:331 Uncaught Error: duplicate name '.mypackage.options.scope' in Type .google.protobuf.FieldOptions
at Type.add (type.js:331)
at tryHandleExtension (root.js:266)
at Root._handleAdd (root.js:294)
at Root._handleAdd (root.js:299)
at Root._handleAdd (root.js:299)
at Namespace.onAdd (object.js:120)
at Root.add (namespace.js:243)
at Root.addJSON (namespace.js:172)
at Function.fromJSON (root.js:51)
at Object../src/app/protos-helper.ts (protos-helper.ts:13)
One way to work around this is to modify tryHandleExtension
in protobufjs/src/root.js
to replace:
extendedType.add(sisterField);
with:
if (!extendedType.get(sisterField.name)) {
extendedType.add(sisterField);
}
ThePlenkov and kulivers
Metadata
Metadata
Assignees
Labels
No labels