Skip to content

Commit

Permalink
Reduce dynamic/message dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
rerost committed Sep 1, 2024
1 parent 5d9b8c3 commit b1e56fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions domain/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
"github.com/rerost/giro/domain/grpcreflectiface"
"github.com/rerost/giro/domain/messagename"
"google.golang.org/protobuf/runtime/protoiface"
)

type JSON []byte
Expand All @@ -20,7 +21,7 @@ type MessageService interface {
ToJSON(ctx context.Context, messageName messagename.MessageName, binary Binary) (JSON, error)
ToBinary(ctx context.Context, messageName messagename.MessageName, json JSON) (Binary, error)
// NOTE: For internal.
ToDynamicMessage(ctx context.Context, messageName messagename.MessageName, json JSON) (*dynamic.Message, error)
ToDynamicMessage(ctx context.Context, messageName messagename.MessageName, json JSON) (protoiface.MessageV1, error)
DynamicMessageToJSON(ctx context.Context, dm *dynamic.Message) (JSON, error)
}

Expand Down Expand Up @@ -112,7 +113,7 @@ func (ms messageServiceImpl) ToBinary(ctx context.Context, messageName messagena
return bin, nil
}

func (ms messageServiceImpl) ToDynamicMessage(ctx context.Context, messageName messagename.MessageName, json JSON) (*dynamic.Message, error) {
func (ms messageServiceImpl) ToDynamicMessage(ctx context.Context, messageName messagename.MessageName, json JSON) (protoiface.MessageV1, error) {
md, err := ms.grpcreflectClient.ResolveMessage(string(messageName))
if err != nil {
return nil, errors.WithStack(err)
Expand Down
8 changes: 7 additions & 1 deletion domain/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/protoadapt"
)

type ServiceService interface {
Expand Down Expand Up @@ -84,7 +86,11 @@ func (ss *serviceServiceImpl) Call(ctx context.Context, serviceName string, meth
return nil, errors.WithStack(err)
}

return ss.messageService.DynamicMessageToJSON(ctx, responseDynamicMessage)
res, err := protojson.Marshal(protoadapt.MessageV2Of(responseDynamicMessage))
if err != nil {
return nil, errors.WithStack(err)
}
return res, nil
}

func (ss *serviceServiceImpl) Ls(ctx context.Context, serviceName *string, methodName *string) ([]Service, error) {
Expand Down

0 comments on commit b1e56fe

Please sign in to comment.