Skip to content

Commit

Permalink
fix: adapt ReadBinary iface
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantxie committed Sep 10, 2024
1 parent dedf95e commit c6a562b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions codec/json/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"

"github.com/bytedance/gopkg/lang/dirtmake"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/cloudwego/kitex/pkg/remote"
"github.com/cloudwego/kitex/pkg/remote/codec"
Expand Down Expand Up @@ -83,11 +84,14 @@ func (jc *JsonCodec) Encode(ctx context.Context, message remote.Message, out rem
}

func (jc *JsonCodec) Decode(ctx context.Context, message remote.Message, in remote.ByteBuffer) error {
length, err := in.ReadBinary(8)
length := dirtmake.Bytes(8, 8)
_, err := in.ReadBinary(length)
if err != nil {
return perrors.NewProtocolError(fmt.Errorf("json decode, read length failed: %w", err))
}
buf, err := in.ReadBinary(int(binary.BigEndian.Uint64(length)))
l := int(binary.BigEndian.Uint64(length))
buf := dirtmake.Bytes(l, l)
_, err = in.ReadBinary(buf)
if err != nil {
return perrors.NewProtocolError(fmt.Errorf("json decode, read data failed: %w", err))
}
Expand Down

0 comments on commit c6a562b

Please sign in to comment.