Skip to content

Commit

Permalink
feat(proto): expose Package for pb Service Descriptor (#83)
Browse files Browse the repository at this point in the history
feat: expose Package for pb Service Descriptor
  • Loading branch information
DMwangnima authored Dec 20, 2024
1 parent 0e99bc3 commit 55704ea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 3 additions & 2 deletions conv/j2p/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (
"time"

"github.com/bytedance/sonic/ast"
"github.com/stretchr/testify/require"
goprotowire "google.golang.org/protobuf/encoding/protowire"

"github.com/cloudwego/dynamicgo/conv"
"github.com/cloudwego/dynamicgo/internal/util_test"
"github.com/cloudwego/dynamicgo/proto"
"github.com/cloudwego/dynamicgo/testdata/kitex_gen/pb/base"
"github.com/cloudwego/dynamicgo/testdata/kitex_gen/pb/example2"
"github.com/stretchr/testify/require"
goprotowire "google.golang.org/protobuf/encoding/protowire"
)

var (
Expand Down
5 changes: 5 additions & 0 deletions proto/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ type ServiceDescriptor struct {
serviceName string
methods map[string]*MethodDescriptor
isCombinedServices bool
packageName string
}

func (s *ServiceDescriptor) Name() string {
Expand All @@ -188,3 +189,7 @@ func (s *ServiceDescriptor) LookupMethodByName(name string) *MethodDescriptor {
func (s *ServiceDescriptor) IsCombinedServices() bool {
return s.isCombinedServices
}

func (s *ServiceDescriptor) PackageName() string {
return s.packageName
}
8 changes: 5 additions & 3 deletions proto/idl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"math"
"unsafe"

"github.com/cloudwego/dynamicgo/internal/util"
"github.com/cloudwego/dynamicgo/meta"
"github.com/jhump/protoreflect/desc"
"github.com/jhump/protoreflect/desc/protoparse"

"github.com/cloudwego/dynamicgo/internal/util"
"github.com/cloudwego/dynamicgo/meta"
)

type compilingInstance struct {
Expand Down Expand Up @@ -118,7 +119,8 @@ func parse(ctx context.Context, fileDesc *desc.FileDescriptor, mode meta.ParseSe
}

sDsc := &ServiceDescriptor{
methods: map[string]*MethodDescriptor{},
methods: map[string]*MethodDescriptor{},
packageName: fileDesc.GetPackage(),
}

structsCache := compilingCache{}
Expand Down
10 changes: 10 additions & 0 deletions proto/idl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

"github.com/cloudwego/dynamicgo/meta"
)

Expand Down Expand Up @@ -108,3 +110,11 @@ func TestIsCombinedServices(t *testing.T) {
}
fmt.Printf("%#v\n", svc)
}

func TestParsePackageName(t *testing.T) {
opts := Options{}
importDirs := []string{"../testdata/idl/"}
svc, err := opts.NewDescriptorFromPath(context.Background(), "basic_example.proto", importDirs...)
require.Nil(t, err, err)
require.Equal(t, "pb3", svc.PackageName(), svc.PackageName())
}

0 comments on commit 55704ea

Please sign in to comment.