Skip to content

Commit

Permalink
fix(attachment): handle transient prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderPoet committed Apr 19, 2024
1 parent ee33062 commit 8f424cf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.13

require (
github.com/apache/dubbo-go-hessian2 v1.12.4
github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b
github.com/cloudwego/kitex v0.8.0
github.com/cloudwego/thriftgo v0.3.3
github.com/stretchr/testify v1.8.2
Expand Down
Empty file modified go_format.sh
100644 → 100755
Empty file.
15 changes: 5 additions & 10 deletions pkg/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (

hessian2_exception "github.com/kitex-contrib/codec-dubbo/pkg/hessian2/exception"

"github.com/kitex-contrib/codec-dubbo/registries"

"github.com/bytedance/gopkg/cloud/metainfo"
"github.com/cloudwego/kitex/pkg/remote"
"github.com/cloudwego/kitex/pkg/remote/codec"
"github.com/kitex-contrib/codec-dubbo/pkg/dubbo_spec"
"github.com/kitex-contrib/codec-dubbo/pkg/hessian2"
"github.com/kitex-contrib/codec-dubbo/pkg/iface"
"github.com/kitex-contrib/codec-dubbo/registries"
)

var _ remote.Codec = (*DubboCodec)(nil)
Expand Down Expand Up @@ -453,22 +453,17 @@ func processAttachments(decoder iface.Decoder, message remote.Message) error {

if attachments, ok := attachmentsRaw.(map[interface{}]interface{}); ok {
transStrMap := map[string]string{}
transIntMap := map[uint16]string{}
for keyRaw, val := range attachments {
if key, ok := keyRaw.(string); ok {
message.Tags()[key] = val
if v, ok := val.(string); ok {
transStrMap[key] = v
}
}
if uint16Key, ok := keyRaw.(uint16); ok {
if v, ok := val.(string); ok {
transIntMap[uint16Key] = v
// The prefix needs to be added
transStrMap[metainfo.PrefixTransient+key] = v
}
}
}

message.TransInfo().PutTransStrInfo(transStrMap)
message.TransInfo().PutTransIntInfo(transIntMap)
return nil
}

Expand Down
16 changes: 11 additions & 5 deletions pkg/dubbo_spec/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ package dubbo_spec

import (
"strconv"
"strings"
"time"

"github.com/bytedance/gopkg/cloud/metainfo"
"github.com/cloudwego/kitex/pkg/remote"
)

Expand All @@ -32,9 +34,11 @@ const (
INTERFACE_KEY = "interface"
VERSION_KEY = "version"
TIMEOUT_KEY = "timeout"

lenPT = len(metainfo.PrefixTransient)
)

type Attachment = map[interface{}]interface{}
type Attachment = map[string]interface{}

func NewAttachment(path, group, iface, version string, timeout time.Duration, transInfo remote.TransInfo) Attachment {
result := Attachment{}
Expand All @@ -53,11 +57,13 @@ func NewAttachment(path, group, iface, version string, timeout time.Duration, tr
if timeout > 0 {
result[TIMEOUT_KEY] = strconv.Itoa(int(timeout.Milliseconds()))
}
for k, v := range transInfo.TransIntInfo() {
result[k] = v
}
for k, v := range transInfo.TransStrInfo() {
result[k] = v
// The prefix needs to be removed
if strings.HasPrefix(k, metainfo.PrefixTransient) {
result[k[lenPT:]] = v
} else {
result[k] = v
}
}
return result
}

0 comments on commit 8f424cf

Please sign in to comment.