Skip to content

Commit

Permalink
fix: add multi params support (#7)
Browse files Browse the repository at this point in the history
* fix: add multi params support

* fix : remove ci auto build

* fix: rm ql
  • Loading branch information
LaurenceLiZhixin authored Jul 26, 2021
1 parent 11b9e6e commit 7f59f2a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 75 deletions.
54 changes: 0 additions & 54 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

33 changes: 20 additions & 13 deletions internal/codec/twoway_codec_impl/twoway_codec_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@

package twoway_codec_impl

import (
perrors "github.com/pkg/errors"
)

import (
"github.com/dubbogo/triple/internal/codec"
"github.com/dubbogo/triple/internal/codec/codec_impl"
proto2 "github.com/dubbogo/triple/internal/codec/proto"
"github.com/dubbogo/triple/internal/codes"
"github.com/dubbogo/triple/internal/status"
"github.com/dubbogo/triple/pkg/common"
"github.com/dubbogo/triple/pkg/common/constant"
)
Expand Down Expand Up @@ -65,12 +63,15 @@ func NewPBWrapperTwoWayCodec(codecName constant.CodecType) (common.TwoWayCodec,
func (h *PBWrapperTwoWayCodec) MarshalRequest(v interface{}) ([]byte, error) {
argsBytes := make([][]byte, 0)
argsTypes := make([]string, 0)
data, err := h.codec.Marshal(v)
if err != nil {
return nil, err
reqList := v.([]interface{})
for _, value := range reqList {
data, err := h.codec.Marshal(value)
if err != nil {
return nil, err
}
argsBytes = append(argsBytes, data)
argsTypes = append(argsTypes, codec.GetArgType(value))
}
argsBytes = append(argsBytes, data)
argsTypes = append(argsTypes, codec.GetArgType(v))

wrapperRequest := &proto2.TripleRequestWrapper{
SerializeType: common.GetCodecInWrapperName(h.codecName),
Expand All @@ -87,12 +88,18 @@ func (h *PBWrapperTwoWayCodec) UnmarshalRequest(data []byte, v interface{}) erro
if err != nil {
return err
}
if len(wrapperRequest.Args) != 1 {
return perrors.New("wrapper request args len is not 1")

paramsInterfaces := v.([]interface{})
if len(paramsInterfaces) != len(wrapperRequest.Args) {
return status.Errorf(codes.Internal, "error ,request params len is %d, but exported method has %d", len(wrapperRequest.Args), len(paramsInterfaces))
}
if err := h.codec.Unmarshal(wrapperRequest.Args[0], v); err != nil {
return err

for idx, value := range wrapperRequest.Args {
if err := h.codec.Unmarshal(value, paramsInterfaces[idx]); err != nil {
return err
}
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/http2_handler/tri_http2_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (hc *H2Controller) UnaryInvoke(ctx context.Context, path string, arg, reply
HeaderField: newHeader,
})
if err != nil {
hc.option.Logger.Errorf("triple unary invoke path %s with addr = %s error = %v", path, hc.address, err)
hc.option.Logger.Error("triple unary invoke path" + path + " with addr = " + hc.address + " error = " + err.Error())
return err
}

Expand Down
11 changes: 7 additions & 4 deletions internal/stream/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (p *unaryProcessor) processUnaryRPC(buf bytes.Buffer, service interface{},
if !ok {
return nil, status.Errorf(codes.Internal, "msgpack provider service doesn't impl TripleUnaryService")
}
reqParam, ok := unaryService.GetReqParamsInteface(methodName)
reqParam, ok := unaryService.GetReqParamsInterfaces(methodName)
if !ok {
return nil, status.Errorf(codes.Internal, "provider unmarshal error: no req param data")
}
Expand All @@ -137,9 +137,12 @@ func (p *unaryProcessor) processUnaryRPC(buf bytes.Buffer, service interface{},
if err = p.twoWayCodec.UnmarshalRequest(readBuf, reqParam); err != nil {
return nil, status.Errorf(codes.Internal, "Unary rpc request unmarshal error: %s", err)
}
args := make([]interface{}, 0, 1)
reqParam = reflect.ValueOf(reqParam).Elem().Interface()
args = append(args, reqParam)
args := make([]interface{}, 0, len(reqParam))
for _, v := range reqParam {
tempParamObj := reflect.ValueOf(v).Elem().Interface()
args = append(args, tempParamObj)
}

reply, err = unaryService.InvokeWithArgs(header.FieldToCtx(), methodName, args)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/common/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ type TripleGrpcService interface {
// TripleUnaryService is normal protocol service (except grpc service), should be implemented by users
type TripleUnaryService interface {
InvokeWithArgs(ctx context.Context, methodName string, arguments []interface{}) (interface{}, error)
GetReqParamsInteface(methodName string) (interface{}, bool)
GetReqParamsInterfaces(methodName string) ([]interface{}, bool)
}
2 changes: 1 addition & 1 deletion pkg/http2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ LOOP:
}

if timeoutFlag {
h.logger.Errorf("unary call %s with addr = %s timeout", path, addr)
h.logger.Error("unary call" + path + " with addr = " + addr + " timeout")
return nil, nil, perrors.Errorf("unary call %s timeout", path)
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/triple/dubbo3_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ func (t *TripleClient) Invoke(methodName string, in []reflect.Value, reply inter
} else {
ctx := in[0].Interface().(context.Context)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
err := t.Request(ctx, "/"+interfaceKey+"/"+methodName, in[1].Interface(), reply)
reqParams := make([]interface{}, 0, len(in)-1)
for idx, v := range in {
if idx > 0 {
reqParams = append(reqParams, v.Interface())
}
}
err := t.Request(ctx, "/"+interfaceKey+"/"+methodName, reqParams, reply)
if err != nil {
return err
}
Expand Down

0 comments on commit 7f59f2a

Please sign in to comment.