You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That's [somewhat] logically reasonable. However, it burdens end-users with determining and keeping track of file builders. It would be a great help to detect this problem inside the module.
Solution
Unfortunately, I'm not familiar with this module and the proto-reflection to propose any meaningful solutions.
My workaround at the moment
var (
fileBuilderRegistry= sync.Map{}
messageBuilderRegistry= sync.Map{}
)
// RegisterFileBuilder registers a file builder.funcRegisterFileBuilder(fb*protobuilder.FileBuilder) {
_, ok:=fileBuilderRegistry.Load(fb.Path())
ifok {
return
}
fileBuilderRegistry.Store(fb.Path(), fb)
for_, cb:=rangefb.Children() {
ifcb, ok:=cb.(*protobuilder.MessageBuilder); ok {
RegisterMessageBuilder(cb)
}
}
}
// RegisterMessageBuilder registers a message builder.funcRegisterMessageBuilder(mb*protobuilder.MessageBuilder) {
key:=string(mb.ParentFile().Package) +"."+string(mb.Name())
_, ok:=messageBuilderRegistry.Load(key)
ifok {
return
}
messageBuilderRegistry.Store(key, mb)
RegisterFileBuilder(mb.ParentFile())
}
// FindMessageBuilder finds a message builder by name.funcFindMessageBuilder(namestring) *protobuilder.MessageBuilder {
mb, ok:=messageBuilderRegistry.Load(name)
if!ok {
returnnil
}
returnmb.(*protobuilder.MessageBuilder) //nolint: forcetypeassert
}
// FromProtoMessage creates a new MessageBuilder from a proto message.funcFromProtoMessage(m proto.Message) (mb*protobuilder.MessageBuilder, errerror) {
mb=FindMessageBuilder(string(m.ProtoReflect().Descriptor().FullName()))
ifmb==nil {
mb, err=protobuilder.FromMessage(m.ProtoReflect().Descriptor())
iferr!=nil {
returnnil, err
}
RegisterMessageBuilder(mb)
}
returnmb, nil
}
The text was updated successfully, but these errors were encountered:
nhatthm
changed the title
[v2] protobuilder doesn't automatically detect builders that point to the same descriptor (or path)v2/protobuilder doesn't automatically detect builders that point to the same descriptor (or path)
Sep 14, 2024
Problem Statement
I have this example
When running this, I get
After debugging, the reason problem is due to
protoreflect/protobuilder/resolver.go
Lines 60 to 64 in 60df127
The module can not detect that the file has been registered here because I have 2 different builders that point to the same file descriptor
protoreflect/protobuilder/resolver.go
Line 89 in 60df127
That's [somewhat] logically reasonable. However, it burdens end-users with determining and keeping track of file builders. It would be a great help to detect this problem inside the module.
Solution
Unfortunately, I'm not familiar with this module and the proto-reflection to propose any meaningful solutions.
My workaround at the moment
The text was updated successfully, but these errors were encountered: