Skip to content
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

feat(go-client): find descriptors by proto fullname #123

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions clients/go/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ func TestClient(t *testing.T) {
field := msg.Fields().ByName("field_one")
assert.NotNil(t, field)
})
t.Run("should get descriptor if package name is not defined", func(t *testing.T) {
msg, err := client.GetDescriptor("Root")
assert.Nil(t, err)
field := msg.Fields().ByName("field_one")
assert.NotNil(t, field)
})
t.Run("should get descriptor if proto package name is not defined but java package is defined", func(t *testing.T) {
msg, err := client.GetDescriptor("test.stencil.Root")
assert.Nil(t, err)
field := msg.Fields().ByName("field_one")
assert.NotNil(t, field)
})
})
t.Run("Parse", func(t *testing.T) {
data, err := getDescriptorData(t, true)
Expand Down
2 changes: 2 additions & 0 deletions clients/go/protoutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func defaultKeyFn(msg protoreflect.MessageDescriptor) string {
pkg := getJavaPackage(file)
if pkg == "" {
return fullName
} else if protoPackage == "" {
return fmt.Sprintf("%s.%s", pkg, fullName)
}
return strings.Replace(fullName, protoPackage, pkg, 1)
}
Expand Down
2 changes: 1 addition & 1 deletion clients/go/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Resolver struct {
func (r *Resolver) Get(className string) (protoreflect.MessageType, bool) {
fullName, ok := r.javaToProtoName[className]
if !ok {
return nil, false
fullName = className
}
msg, err := r.types.FindMessageByName(protoreflect.FullName(fullName))
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions clients/go/test_data/3.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
syntax = "proto3";
option java_package = "test.stencil";
message Root {
int64 field_one = 1;
}