From bab39191983255fbd3a9d794caa817758cd0dda4 Mon Sep 17 00:00:00 2001 From: yuxuanwang <464621663@qq.com> Date: Wed, 16 Aug 2023 22:40:24 +0800 Subject: [PATCH] feat: change related module and struct name from hessian2 to dubbo, enhance exception support --- README.md | 4 +- go.mod | 2 +- go_format.sh | 2 +- pkg/codec.go | 134 +++++++++++------- pkg/data/null.go | 2 +- pkg/decoder.go | 4 +- pkg/deserializer.go | 4 +- pkg/{dubbo => dubbo_spec}/attachment.go | 2 +- pkg/{dubbo => dubbo_spec}/header.go | 2 +- pkg/{dubbo => dubbo_spec}/header_test.go | 2 +- pkg/{dubbo => dubbo_spec}/parameter.go | 2 +- pkg/{dubbo => dubbo_spec}/parameter_test.go | 2 +- pkg/{dubbo => dubbo_spec}/payload.go | 4 +- pkg/{dubbo => dubbo_spec}/service.go | 4 +- pkg/{dubbo => dubbo_spec}/utils.go | 2 +- pkg/encoder.go | 6 +- pkg/hessian_protocol.go | 4 +- pkg/serializer.go | 4 +- tests/kitex/client/client.go | 2 +- tests/kitex/go.mod | 6 +- tests/kitex/handler.go | 2 +- tests/kitex/kitex_gen/echo/k-api.go | 2 +- .../kitex_gen/echo/testservice/client.go | 6 +- .../kitex_gen/echo/testservice/invoker.go | 2 +- .../kitex_gen/echo/testservice/server.go | 6 +- .../kitex_gen/echo/testservice/testservice.go | 2 +- tests/kitex/main.go | 2 +- tests/kitex/readme.md | 4 +- 28 files changed, 123 insertions(+), 97 deletions(-) rename pkg/{dubbo => dubbo_spec}/attachment.go (98%) rename pkg/{dubbo => dubbo_spec}/header.go (99%) rename pkg/{dubbo => dubbo_spec}/header_test.go (99%) rename pkg/{dubbo => dubbo_spec}/parameter.go (99%) rename pkg/{dubbo => dubbo_spec}/parameter_test.go (99%) rename pkg/{dubbo => dubbo_spec}/payload.go (96%) rename pkg/{dubbo => dubbo_spec}/service.go (96%) rename pkg/{dubbo => dubbo_spec}/utils.go (99%) diff --git a/README.md b/README.md index aa63fccf..fbac279e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# codec-hessian2 +# codec-dubbo --- @@ -6,7 +6,7 @@ > **Notice: When decoding, the java version of hessian will default skip and ignore non-exist fields.** -It's a golang hessian library used by kitex (https://github.com/cloudwego/kitex). +It's a golang dubbo library used by kitex (https://github.com/cloudwego/kitex). ## Feature List diff --git a/go.mod b/go.mod index 0582655c..615376d2 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/kitex-contrib/codec-hessian2 +module github.com/kitex-contrib/codec-dubbo go 1.13 diff --git a/go_format.sh b/go_format.sh index 4031b23a..d9601d69 100644 --- a/go_format.sh +++ b/go_format.sh @@ -17,7 +17,7 @@ # format go imports style go install golang.org/x/tools/cmd/goimports -goimports -local git@github.com/kitex-contrib/codec-hessian2 -w . +goimports -local git@github.com/kitex-contrib/codec-dubbo -w . # format licence style go install github.com/apache/skywalking-eyes/cmd/license-eye@latest diff --git a/pkg/codec.go b/pkg/codec.go index 666cd316..e9bb2e98 100644 --- a/pkg/codec.go +++ b/pkg/codec.go @@ -17,57 +17,59 @@ * limitations under the License. */ -package hessian2 +package dubbo import ( "context" "errors" "fmt" - commons "github.com/kitex-contrib/codec-hessian2/pkg/common" + commons "github.com/kitex-contrib/codec-dubbo/pkg/common" hessian "github.com/apache/dubbo-go-hessian2" "github.com/apache/dubbo-go-hessian2/java_exception" "github.com/cloudwego/kitex/pkg/remote" "github.com/cloudwego/kitex/pkg/remote/codec" - "github.com/kitex-contrib/codec-hessian2/pkg/dubbo" - "github.com/kitex-contrib/codec-hessian2/pkg/iface" + "github.com/kitex-contrib/codec-dubbo/pkg/dubbo_spec" + "github.com/kitex-contrib/codec-dubbo/pkg/iface" ) -var _ remote.Codec = (*Hessian2Codec)(nil) +var _ remote.Codec = (*DubboCodec)(nil) -// Hessian2Codec NewHessian2Codec creates the hessian2 codec. -type Hessian2Codec struct{} +// DubboCodec NewDubboCodec creates the dubbo codec. +type DubboCodec struct{} -// NewHessian2Codec creates a new codec instance. -func NewHessian2Codec() *Hessian2Codec { - return &Hessian2Codec{} +// NewDubboCodec creates a new codec instance. +func NewDubboCodec() *DubboCodec { + return &DubboCodec{} } // Name codec name -func (m *Hessian2Codec) Name() string { - return "hessian2" +func (m *DubboCodec) Name() string { + return "dubbo" } // Marshal encode method -func (m *Hessian2Codec) Encode(ctx context.Context, message remote.Message, out remote.ByteBuffer) error { +func (m *DubboCodec) Encode(ctx context.Context, message remote.Message, out remote.ByteBuffer) error { var payload []byte var err error - var status dubbo.StatusCode + var status dubbo_spec.StatusCode msgType := message.MessageType() switch msgType { case remote.Call, remote.Oneway: payload, err = m.encodeRequestPayload(ctx, message) case remote.Exception: payload, err = m.encodeExceptionPayload(ctx, message) - // use StatusOK by default, regardless of whether it is Reply or Exception - status = dubbo.StatusOK + // todo(DMwangnima): refer to exception processing logic of dubbo-java, use status to determine if this exception + // is in outside layer.(eg. non-exist InterfaceName) + // for now, use StatusOK by default, regardless of whether it is in outside layer. + status = dubbo_spec.StatusOK case remote.Reply: payload, err = m.encodeResponsePayload(ctx, message) - status = dubbo.StatusOK + status = dubbo_spec.StatusOK case remote.Heartbeat: payload, err = m.encodeHeartbeatPayload(ctx, message) - status = dubbo.StatusOK + status = dubbo_spec.StatusOK default: return fmt.Errorf("unsupported MessageType: %v", msgType) } @@ -90,11 +92,11 @@ func (m *Hessian2Codec) Encode(ctx context.Context, message remote.Message, out return nil } -func (m *Hessian2Codec) encodeRequestPayload(ctx context.Context, message remote.Message) (buf []byte, err error) { +func (m *DubboCodec) encodeRequestPayload(ctx context.Context, message remote.Message) (buf []byte, err error) { encoder := hessian.NewEncoder() - service := &dubbo.Service{ - ProtocolVersion: dubbo.DEFAULT_DUBBO_PROTOCOL_VERSION, + service := &dubbo_spec.Service{ + ProtocolVersion: dubbo_spec.DEFAULT_DUBBO_PROTOCOL_VERSION, // todo: should be message.RPCInfo().Invocation.ServiceName Path: message.RPCInfo().To().ServiceName(), // todo: kitex mapping @@ -119,13 +121,13 @@ func (m *Hessian2Codec) encodeRequestPayload(ctx context.Context, message remote return encoder.Buffer(), nil } -func (m *Hessian2Codec) encodeResponsePayload(ctx context.Context, message remote.Message) (buf []byte, err error) { +func (m *DubboCodec) encodeResponsePayload(ctx context.Context, message remote.Message) (buf []byte, err error) { encoder := hessian.NewEncoder() - var payloadType dubbo.PayloadType + var payloadType dubbo_spec.PayloadType if len(message.Tags()) != 0 { - payloadType = dubbo.RESPONSE_VALUE_WITH_ATTACHMENTS + payloadType = dubbo_spec.RESPONSE_VALUE_WITH_ATTACHMENTS } else { - payloadType = dubbo.RESPONSE_VALUE + payloadType = dubbo_spec.RESPONSE_VALUE } if err := encoder.Encode(payloadType); err != nil { @@ -143,7 +145,7 @@ func (m *Hessian2Codec) encodeResponsePayload(ctx context.Context, message remot } // encode attachments if needed - if dubbo.IsAttachmentsPayloadType(payloadType) { + if dubbo_spec.IsAttachmentsPayloadType(payloadType) { if err := encoder.Encode(message.Tags()); err != nil { return nil, err } @@ -152,13 +154,13 @@ func (m *Hessian2Codec) encodeResponsePayload(ctx context.Context, message remot return encoder.Buffer(), nil } -func (m *Hessian2Codec) encodeExceptionPayload(ctx context.Context, message remote.Message) (buf []byte, err error) { +func (m *DubboCodec) encodeExceptionPayload(ctx context.Context, message remote.Message) (buf []byte, err error) { encoder := hessian.NewEncoder() - var payloadType dubbo.PayloadType + var payloadType dubbo_spec.PayloadType if len(message.Tags()) != 0 { - payloadType = dubbo.RESPONSE_WITH_EXCEPTION_WITH_ATTACHMENTS + payloadType = dubbo_spec.RESPONSE_WITH_EXCEPTION_WITH_ATTACHMENTS } else { - payloadType = dubbo.RESPONSE_WITH_EXCEPTION + payloadType = dubbo_spec.RESPONSE_WITH_EXCEPTION } if err := encoder.Encode(payloadType); err != nil { @@ -181,7 +183,7 @@ func (m *Hessian2Codec) encodeExceptionPayload(ctx context.Context, message remo } } - if dubbo.IsAttachmentsPayloadType(payloadType) { + if dubbo_spec.IsAttachmentsPayloadType(payloadType) { if err := encoder.Encode(message.Tags()); err != nil { return nil, err } @@ -196,7 +198,7 @@ func (m *Hessian2Codec) encodeExceptionPayload(ctx context.Context, message remo // Arrays.equals(payload, getNullBytesOf(getSerializationById(proto))) // For hessian2, NullByte is 'N'. // As a result, we need to encode nil in heartbeat response body for both dubbo-go side and dubbo-java side. -func (m *Hessian2Codec) encodeHeartbeatPayload(ctx context.Context, message remote.Message) (buf []byte, err error) { +func (m *DubboCodec) encodeHeartbeatPayload(ctx context.Context, message remote.Message) (buf []byte, err error) { encoder := hessian.NewEncoder() if err := encoder.Encode(nil); err != nil { @@ -206,26 +208,26 @@ func (m *Hessian2Codec) encodeHeartbeatPayload(ctx context.Context, message remo return encoder.Buffer(), nil } -func (m *Hessian2Codec) buildDubboHeader(message remote.Message, status dubbo.StatusCode, size int) *dubbo.DubboHeader { +func (m *DubboCodec) buildDubboHeader(message remote.Message, status dubbo_spec.StatusCode, size int) *dubbo_spec.DubboHeader { msgType := message.MessageType() - return &dubbo.DubboHeader{ + return &dubbo_spec.DubboHeader{ IsRequest: msgType == remote.Call || msgType == remote.Oneway, // todo(DMwangnima): message contains heartbeat information or heartbeat flag passed in IsEvent: false, IsOneWay: msgType == remote.Oneway, - SerializationID: dubbo.SERIALIZATION_ID_HESSIAN, + SerializationID: dubbo_spec.SERIALIZATION_ID_HESSIAN, Status: status, RequestID: uint64(message.RPCInfo().Invocation().SeqID()), DataLength: uint32(size), } } -func (m *Hessian2Codec) messageData(message remote.Message, e iface.Encoder) error { +func (m *DubboCodec) messageData(message remote.Message, e iface.Encoder) error { data, ok := message.Data().(iface.Message) if !ok { return fmt.Errorf("invalid data: not hessian2.MessageWriter") } - types, err := dubbo.GetTypes(data) + types, err := dubbo_spec.GetTypes(data) if err != nil { return err } @@ -235,7 +237,7 @@ func (m *Hessian2Codec) messageData(message remote.Message, e iface.Encoder) err return data.Encode(e) } -func (m *Hessian2Codec) messageServiceInfo(ctx context.Context, service *dubbo.Service, e iface.Encoder) error { +func (m *DubboCodec) messageServiceInfo(ctx context.Context, service *dubbo_spec.Service, e iface.Encoder) error { if err := e.Encode(service.ProtocolVersion); err != nil { return err } @@ -251,8 +253,8 @@ func (m *Hessian2Codec) messageServiceInfo(ctx context.Context, service *dubbo.S return nil } -func (m *Hessian2Codec) messageAttachment(ctx context.Context, service *dubbo.Service, e iface.Encoder) error { - attachment := dubbo.NewAttachment( +func (m *DubboCodec) messageAttachment(ctx context.Context, service *dubbo_spec.Service, e iface.Encoder) error { + attachment := dubbo_spec.NewAttachment( service.Path, service.Group, service.Path, @@ -263,9 +265,9 @@ func (m *Hessian2Codec) messageAttachment(ctx context.Context, service *dubbo.Se } // Unmarshal decode method -func (m *Hessian2Codec) Decode(ctx context.Context, message remote.Message, in remote.ByteBuffer) error { +func (m *DubboCodec) Decode(ctx context.Context, message remote.Message, in remote.ByteBuffer) error { // parse header part - header := new(dubbo.DubboHeader) + header := new(dubbo_spec.DubboHeader) if err := header.Decode(in); err != nil { return err } @@ -281,10 +283,14 @@ func (m *Hessian2Codec) Decode(ctx context.Context, message remote.Message, in r } return m.decodeRequestBody(ctx, header, message, in) } + + if header.Status != dubbo_spec.StatusOK { + return m.decodeExceptionBody(ctx, header, message, in) + } return m.decodeResponseBody(ctx, header, message, in) } -func (m *Hessian2Codec) decodeEventBody(ctx context.Context, header *dubbo.DubboHeader, message remote.Message, in remote.ByteBuffer) error { +func (m *DubboCodec) decodeEventBody(ctx context.Context, header *dubbo_spec.DubboHeader, message remote.Message, in remote.ByteBuffer) error { body, err := readBody(header, in) if err != nil { return err @@ -299,14 +305,14 @@ func (m *Hessian2Codec) decodeEventBody(ctx context.Context, header *dubbo.Dubbo return nil } -func (m *Hessian2Codec) decodeRequestBody(ctx context.Context, header *dubbo.DubboHeader, message remote.Message, in remote.ByteBuffer) error { +func (m *DubboCodec) decodeRequestBody(ctx context.Context, header *dubbo_spec.DubboHeader, message remote.Message, in remote.ByteBuffer) error { body, err := readBody(header, in) if err != nil { return err } decoder := hessian.NewDecoder(body) - service := new(dubbo.Service) + service := new(dubbo_spec.Service) if err := service.Decode(decoder); err != nil { return err } @@ -340,19 +346,39 @@ func (m *Hessian2Codec) decodeRequestBody(ctx context.Context, header *dubbo.Dub return nil } -func (m *Hessian2Codec) decodeResponseBody(ctx context.Context, header *dubbo.DubboHeader, message remote.Message, in remote.ByteBuffer) error { +// decodeExceptionBody is responsible for processing exception in the outer layer which means business logic +// in the remoting service has not been invoked. (eg. wrong request with non-exist InterfaceName) +func (m *DubboCodec) decodeExceptionBody(ctx context.Context, header *dubbo_spec.DubboHeader, message remote.Message, in remote.ByteBuffer) error { + body, err := readBody(header, in) + if err != nil { + return err + } + + decoder := hessian.NewDecoder(body) + exception, err := decoder.Decode() + if err != nil { + return err + } + exceptionStr, ok := exception.(string) + if !ok { + return fmt.Errorf("exception %v is not of string", exception) + } + return fmt.Errorf("dubbo side exception: %s", exceptionStr) +} + +func (m *DubboCodec) decodeResponseBody(ctx context.Context, header *dubbo_spec.DubboHeader, message remote.Message, in remote.ByteBuffer) error { body, err := readBody(header, in) if err != nil { return err } decoder := hessian.NewDecoder(body) - payloadType, err := dubbo.DecodePayloadType(decoder) + payloadType, err := dubbo_spec.DecodePayloadType(decoder) if err != nil { return err } switch payloadType { - case dubbo.RESPONSE_VALUE, dubbo.RESPONSE_VALUE_WITH_ATTACHMENTS: + case dubbo_spec.RESPONSE_VALUE, dubbo_spec.RESPONSE_VALUE_WITH_ATTACHMENTS: msg, ok := message.Data().(iface.Message) if !ok { return fmt.Errorf("invalid data %v: not hessian2.MessageReader", msg) @@ -360,18 +386,18 @@ func (m *Hessian2Codec) decodeResponseBody(ctx context.Context, header *dubbo.Du if err := msg.Decode(decoder); err != nil { return err } - if dubbo.IsAttachmentsPayloadType(payloadType) { + if dubbo_spec.IsAttachmentsPayloadType(payloadType) { if err := processAttachments(decoder, message); err != nil { return err } } // business logic exception - case dubbo.RESPONSE_WITH_EXCEPTION, dubbo.RESPONSE_WITH_EXCEPTION_WITH_ATTACHMENTS: + case dubbo_spec.RESPONSE_WITH_EXCEPTION, dubbo_spec.RESPONSE_WITH_EXCEPTION_WITH_ATTACHMENTS: exception, err := decoder.Decode() if err != nil { return err } - if dubbo.IsAttachmentsPayloadType(payloadType) { + if dubbo_spec.IsAttachmentsPayloadType(payloadType) { if err := processAttachments(decoder, message); err != nil { return err } @@ -380,8 +406,8 @@ func (m *Hessian2Codec) decodeResponseBody(ctx context.Context, header *dubbo.Du return exceptionErr } return fmt.Errorf("dubbo side exception: %v", exception) - case dubbo.RESPONSE_NULL_VALUE, dubbo.RESPONSE_NULL_VALUE_WITH_ATTACHMENTS: - if dubbo.IsAttachmentsPayloadType(payloadType) { + case dubbo_spec.RESPONSE_NULL_VALUE, dubbo_spec.RESPONSE_NULL_VALUE_WITH_ATTACHMENTS: + if dubbo_spec.IsAttachmentsPayloadType(payloadType) { if err := processAttachments(decoder, message); err != nil { return err } @@ -411,7 +437,7 @@ func processAttachments(decoder iface.Decoder, message remote.Message) error { return fmt.Errorf("unsupported attachments: %v", attachmentsRaw) } -func readBody(header *dubbo.DubboHeader, in remote.ByteBuffer) ([]byte, error) { +func readBody(header *dubbo_spec.DubboHeader, in remote.ByteBuffer) ([]byte, error) { length := int(header.DataLength) if in.ReadableLen() < length { return nil, errors.New("invalid dubbo package with body length being less than header specified") diff --git a/pkg/data/null.go b/pkg/data/null.go index e338a639..fcfe1b70 100644 --- a/pkg/data/null.go +++ b/pkg/data/null.go @@ -20,7 +20,7 @@ package hessian2 import ( - commons "github.com/kitex-contrib/codec-hessian2/pkg/common" + commons "github.com/kitex-contrib/codec-dubbo/pkg/common" ) // EncodeNull ::= 'N' diff --git a/pkg/decoder.go b/pkg/decoder.go index 09906b8e..befa85b2 100644 --- a/pkg/decoder.go +++ b/pkg/decoder.go @@ -17,14 +17,14 @@ * limitations under the License. */ -package hessian2 +package dubbo import ( "bufio" "bytes" "fmt" - commons "github.com/kitex-contrib/codec-hessian2/pkg/common" + commons "github.com/kitex-contrib/codec-dubbo/pkg/common" ) func NewDecoder(r bufio.Reader) *Decoder { diff --git a/pkg/deserializer.go b/pkg/deserializer.go index 8a09df88..aa330fcf 100644 --- a/pkg/deserializer.go +++ b/pkg/deserializer.go @@ -17,13 +17,13 @@ * limitations under the License. */ -package hessian2 +package dubbo import ( "bytes" "context" - "github.com/kitex-contrib/codec-hessian2/pkg/iface" + "github.com/kitex-contrib/codec-dubbo/pkg/iface" ) type BaseDeserializer struct { diff --git a/pkg/dubbo/attachment.go b/pkg/dubbo_spec/attachment.go similarity index 98% rename from pkg/dubbo/attachment.go rename to pkg/dubbo_spec/attachment.go index 0cecf2f8..087055d2 100644 --- a/pkg/dubbo/attachment.go +++ b/pkg/dubbo_spec/attachment.go @@ -17,7 +17,7 @@ * limitations under the License. */ -package dubbo +package dubbo_spec import ( "strconv" diff --git a/pkg/dubbo/header.go b/pkg/dubbo_spec/header.go similarity index 99% rename from pkg/dubbo/header.go rename to pkg/dubbo_spec/header.go index 3f037f75..071de628 100644 --- a/pkg/dubbo/header.go +++ b/pkg/dubbo_spec/header.go @@ -17,7 +17,7 @@ * limitations under the License. */ -package dubbo +package dubbo_spec import ( "encoding/binary" diff --git a/pkg/dubbo/header_test.go b/pkg/dubbo_spec/header_test.go similarity index 99% rename from pkg/dubbo/header_test.go rename to pkg/dubbo_spec/header_test.go index 953e707f..8be91fda 100644 --- a/pkg/dubbo/header_test.go +++ b/pkg/dubbo_spec/header_test.go @@ -17,7 +17,7 @@ * limitations under the License. */ -package dubbo +package dubbo_spec import ( "reflect" diff --git a/pkg/dubbo/parameter.go b/pkg/dubbo_spec/parameter.go similarity index 99% rename from pkg/dubbo/parameter.go rename to pkg/dubbo_spec/parameter.go index de3cf087..8588f55e 100644 --- a/pkg/dubbo/parameter.go +++ b/pkg/dubbo_spec/parameter.go @@ -21,7 +21,7 @@ * development team for their valuable contribution. */ -package dubbo +package dubbo_spec import ( "fmt" diff --git a/pkg/dubbo/parameter_test.go b/pkg/dubbo_spec/parameter_test.go similarity index 99% rename from pkg/dubbo/parameter_test.go rename to pkg/dubbo_spec/parameter_test.go index 4523089d..0e86a0a0 100644 --- a/pkg/dubbo/parameter_test.go +++ b/pkg/dubbo_spec/parameter_test.go @@ -17,7 +17,7 @@ * limitations under the License. */ -package dubbo +package dubbo_spec import ( "fmt" diff --git a/pkg/dubbo/payload.go b/pkg/dubbo_spec/payload.go similarity index 96% rename from pkg/dubbo/payload.go rename to pkg/dubbo_spec/payload.go index 8c1d7ef4..7000bb4d 100644 --- a/pkg/dubbo/payload.go +++ b/pkg/dubbo_spec/payload.go @@ -17,12 +17,12 @@ * limitations under the License. */ -package dubbo +package dubbo_spec import ( "fmt" - "github.com/kitex-contrib/codec-hessian2/pkg/iface" + "github.com/kitex-contrib/codec-dubbo/pkg/iface" ) type PayloadType int32 diff --git a/pkg/dubbo/service.go b/pkg/dubbo_spec/service.go similarity index 96% rename from pkg/dubbo/service.go rename to pkg/dubbo_spec/service.go index 03c9e518..65edad73 100644 --- a/pkg/dubbo/service.go +++ b/pkg/dubbo_spec/service.go @@ -17,13 +17,13 @@ * limitations under the License. */ -package dubbo +package dubbo_spec import ( "fmt" "time" - "github.com/kitex-contrib/codec-hessian2/pkg/iface" + "github.com/kitex-contrib/codec-dubbo/pkg/iface" ) const DEFAULT_DUBBO_PROTOCOL_VERSION = "2.0.2" diff --git a/pkg/dubbo/utils.go b/pkg/dubbo_spec/utils.go similarity index 99% rename from pkg/dubbo/utils.go rename to pkg/dubbo_spec/utils.go index 4f0bad60..79697d70 100644 --- a/pkg/dubbo/utils.go +++ b/pkg/dubbo_spec/utils.go @@ -21,7 +21,7 @@ * development team for their valuable contribution. */ -package dubbo +package dubbo_spec import ( "bytes" diff --git a/pkg/encoder.go b/pkg/encoder.go index b85ef86a..e10561c9 100644 --- a/pkg/encoder.go +++ b/pkg/encoder.go @@ -17,7 +17,7 @@ * limitations under the License. */ -package hessian2 +package dubbo import ( "bufio" @@ -25,8 +25,8 @@ import ( "fmt" "reflect" - hessian2 "github.com/kitex-contrib/codec-hessian2/pkg/data" - "github.com/kitex-contrib/codec-hessian2/pkg/iface" + hessian2 "github.com/kitex-contrib/codec-dubbo/pkg/data" + "github.com/kitex-contrib/codec-dubbo/pkg/iface" ) var _ iface.Encoder = (*Encoder)(nil) diff --git a/pkg/hessian_protocol.go b/pkg/hessian_protocol.go index 67fb0d06..041c919c 100644 --- a/pkg/hessian_protocol.go +++ b/pkg/hessian_protocol.go @@ -17,7 +17,7 @@ * limitations under the License. */ -package hessian2 +package dubbo import ( "bytes" @@ -25,7 +25,7 @@ import ( "sync" "github.com/cloudwego/kitex/pkg/utils" - "github.com/kitex-contrib/codec-hessian2/pkg/iface" + "github.com/kitex-contrib/codec-dubbo/pkg/iface" ) // must be strict read & strict write diff --git a/pkg/serializer.go b/pkg/serializer.go index 2f3d9cbe..49740890 100644 --- a/pkg/serializer.go +++ b/pkg/serializer.go @@ -17,13 +17,13 @@ * limitations under the License. */ -package hessian2 +package dubbo import ( "bytes" "context" - "github.com/kitex-contrib/codec-hessian2/pkg/iface" + "github.com/kitex-contrib/codec-dubbo/pkg/iface" ) type BaseSerializer struct { diff --git a/tests/kitex/client/client.go b/tests/kitex/client/client.go index a3b610c5..38a11938 100644 --- a/tests/kitex/client/client.go +++ b/tests/kitex/client/client.go @@ -5,7 +5,7 @@ import ( "github.com/cloudwego/kitex/client" "github.com/cloudwego/kitex/pkg/klog" - "github.com/kitex-contrib/codec-hessian2/tests/kitex/kitex_gen/echo/testservice" + "github.com/kitex-contrib/codec-dubbo/tests/kitex/kitex_gen/echo/testservice" ) func main() { diff --git a/tests/kitex/go.mod b/tests/kitex/go.mod index dc171317..838a518c 100644 --- a/tests/kitex/go.mod +++ b/tests/kitex/go.mod @@ -1,14 +1,14 @@ -module github.com/kitex-contrib/codec-hessian2/tests/kitex +module github.com/kitex-contrib/codec-dubbo/tests/kitex go 1.18 require ( github.com/apache/dubbo-go-hessian2 v1.12.2 github.com/cloudwego/kitex v0.6.2-0.20230815060351-88ea60530d40 - github.com/kitex-contrib/codec-hessian2 v0.0.0-20230721121604-c37a28c79a02 + github.com/kitex-contrib/codec-dubbo v0.0.0-20230721121604-c37a28c79a02 ) -replace github.com/kitex-contrib/codec-hessian2 => ../../ +replace github.com/kitex-contrib/codec-dubbo => ../../ require ( github.com/apache/thrift v0.13.0 // indirect diff --git a/tests/kitex/handler.go b/tests/kitex/handler.go index b3100663..2d9e5948 100644 --- a/tests/kitex/handler.go +++ b/tests/kitex/handler.go @@ -4,7 +4,7 @@ import ( "context" "errors" - echo "github.com/kitex-contrib/codec-hessian2/tests/kitex/kitex_gen/echo" + echo "github.com/kitex-contrib/codec-dubbo/tests/kitex/kitex_gen/echo" ) // TestServiceImpl implements the last service interface defined in the IDL. diff --git a/tests/kitex/kitex_gen/echo/k-api.go b/tests/kitex/kitex_gen/echo/k-api.go index 74681afa..173717d6 100644 --- a/tests/kitex/kitex_gen/echo/k-api.go +++ b/tests/kitex/kitex_gen/echo/k-api.go @@ -6,7 +6,7 @@ import ( "reflect" "strings" - hessian2 "github.com/kitex-contrib/codec-hessian2/pkg/iface" + hessian2 "github.com/kitex-contrib/codec-dubbo/pkg/iface" ) // unused protection diff --git a/tests/kitex/kitex_gen/echo/testservice/client.go b/tests/kitex/kitex_gen/echo/testservice/client.go index e356d80d..dd0a92b3 100644 --- a/tests/kitex/kitex_gen/echo/testservice/client.go +++ b/tests/kitex/kitex_gen/echo/testservice/client.go @@ -5,8 +5,8 @@ import ( "github.com/cloudwego/kitex/client" "github.com/cloudwego/kitex/client/callopt" - hessian2 "github.com/kitex-contrib/codec-hessian2/pkg" - "github.com/kitex-contrib/codec-hessian2/tests/kitex/kitex_gen/echo" + dubbo "github.com/kitex-contrib/codec-dubbo/pkg" + "github.com/kitex-contrib/codec-dubbo/tests/kitex/kitex_gen/echo" ) // Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. @@ -19,7 +19,7 @@ type Client interface { func NewClient(destService string, opts ...client.Option) (Client, error) { var options []client.Option options = append(options, client.WithDestService(destService)) - options = append(options, client.WithCodec(hessian2.NewHessian2Codec())) + options = append(options, client.WithCodec(dubbo.NewDubboCodec())) options = append(options, opts...) diff --git a/tests/kitex/kitex_gen/echo/testservice/invoker.go b/tests/kitex/kitex_gen/echo/testservice/invoker.go index 2dfa4ab8..de9b8ebb 100644 --- a/tests/kitex/kitex_gen/echo/testservice/invoker.go +++ b/tests/kitex/kitex_gen/echo/testservice/invoker.go @@ -2,7 +2,7 @@ package testservice import ( "github.com/cloudwego/kitex/server" - "github.com/kitex-contrib/codec-hessian2/tests/kitex/kitex_gen/echo" + "github.com/kitex-contrib/codec-dubbo/tests/kitex/kitex_gen/echo" ) // NewInvoker creates a server.Invoker with the given handler and options. diff --git a/tests/kitex/kitex_gen/echo/testservice/server.go b/tests/kitex/kitex_gen/echo/testservice/server.go index 894f8581..c6bd61be 100644 --- a/tests/kitex/kitex_gen/echo/testservice/server.go +++ b/tests/kitex/kitex_gen/echo/testservice/server.go @@ -2,8 +2,8 @@ package testservice import ( "github.com/cloudwego/kitex/server" - hessian2 "github.com/kitex-contrib/codec-hessian2/pkg" - "github.com/kitex-contrib/codec-hessian2/tests/kitex/kitex_gen/echo" + dubbo "github.com/kitex-contrib/codec-dubbo/pkg" + "github.com/kitex-contrib/codec-dubbo/tests/kitex/kitex_gen/echo" ) // NewServer creates a server.Server with the given handler and options. @@ -11,7 +11,7 @@ func NewServer(handler echo.TestService, opts ...server.Option) server.Server { var options []server.Option options = append(options, opts...) - options = append(options, server.WithCodec(hessian2.NewHessian2Codec())) + options = append(options, server.WithCodec(dubbo.NewDubboCodec())) svr := server.NewServer(options...) if err := svr.RegisterService(serviceInfo(), handler); err != nil { diff --git a/tests/kitex/kitex_gen/echo/testservice/testservice.go b/tests/kitex/kitex_gen/echo/testservice/testservice.go index b18c67d6..ceb9f1e6 100644 --- a/tests/kitex/kitex_gen/echo/testservice/testservice.go +++ b/tests/kitex/kitex_gen/echo/testservice/testservice.go @@ -5,7 +5,7 @@ import ( "github.com/cloudwego/kitex/client" kitex "github.com/cloudwego/kitex/pkg/serviceinfo" - "github.com/kitex-contrib/codec-hessian2/tests/kitex/kitex_gen/echo" + "github.com/kitex-contrib/codec-dubbo/tests/kitex/kitex_gen/echo" ) func serviceInfo() *kitex.ServiceInfo { diff --git a/tests/kitex/main.go b/tests/kitex/main.go index 076a1e0a..c3c6a491 100644 --- a/tests/kitex/main.go +++ b/tests/kitex/main.go @@ -6,7 +6,7 @@ import ( "github.com/cloudwego/kitex/server" - echo "github.com/kitex-contrib/codec-hessian2/tests/kitex/kitex_gen/echo/testservice" + echo "github.com/kitex-contrib/codec-dubbo/tests/kitex/kitex_gen/echo/testservice" ) func main() { diff --git a/tests/kitex/readme.md b/tests/kitex/readme.md index d0855c4b..7b5c2865 100644 --- a/tests/kitex/readme.md +++ b/tests/kitex/readme.md @@ -31,11 +31,11 @@ Need to implement `hessian.POJO` for these structs (`JavaClassName() string`) * Client: kitex_gen/echo/testservice/client.go ```go -options = append(options, client.WithCodec(hessian2.NewHessian2Codec())) +options = append(options, client.WithCodec(dubbo.NewDubboCodec())) ``` * Server: kitex_gen/echo/testservice/server.go ```go -options = append(options, server.WithCodec(hessian2.NewHessian2Codec())) +options = append(options, server.WithCodec(dubbo.NewDubboCodec())) ```