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 18, 2024
1 parent ee33062 commit d2f5546
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 4 additions & 8 deletions pkg/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"context"
"fmt"

"github.com/bytedance/gopkg/cloud/metainfo"
hessian2_exception "github.com/kitex-contrib/codec-dubbo/pkg/hessian2/exception"

"github.com/kitex-contrib/codec-dubbo/registries"
Expand Down Expand Up @@ -453,22 +454,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
15 changes: 10 additions & 5 deletions pkg/dubbo_spec/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strconv"
"time"

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

Expand All @@ -32,9 +33,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 +56,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 len(k) > lenPT {
result[k[lenPT:]] = v
} else {
result[k] = v
}
}
return result
}

0 comments on commit d2f5546

Please sign in to comment.