cvictory commented on a change in pull request #494:
URL: https://github.com/apache/dubbo-go/pull/494#discussion_r415296263



##########
File path: protocol/dubbo/dubbo_codec.go
##########
@@ -0,0 +1,297 @@
+package dubbo
+
+import (
+       "bufio"
+       "bytes"
+       "fmt"
+       hessian "github.com/apache/dubbo-go-hessian2"
+       "github.com/apache/dubbo-go/common/constant"
+       "github.com/apache/dubbo-go/common/logger"
+       "github.com/apache/dubbo-go/protocol"
+       "github.com/apache/dubbo-go/protocol/invocation"
+       "github.com/apache/dubbo-go/remoting"
+       perrors "github.com/pkg/errors"
+       "strconv"
+       "time"
+)
+
+//SerialID serial ID
+type SerialID byte
+type SequenceType int64
+
+const (
+       // S_Dubbo dubbo serial id
+       S_Dubbo SerialID = 2
+)
+
+// DubboPackage ...
+type DubboPackage struct {
+       Header  hessian.DubboHeader
+       Service hessian.Service
+       Body    interface{}
+       Err     error
+}
+
+func (p DubboPackage) String() string {
+       return fmt.Sprintf("DubboPackage: Header-%v, Path-%v, Body-%v", 
p.Header, p.Service, p.Body)
+}
+
+//
+//// Marshal ...
+//func (p *DubboPackage) Marshal() (*bytes.Buffer, error) {
+//     codec := hessian.NewHessianCodec(nil)
+//
+//     pkg, err := codec.Write(p.Service, p.Header, p.Body)
+//     if err != nil {
+//             return nil, perrors.WithStack(err)
+//     }
+//
+//     return bytes.NewBuffer(pkg), nil
+//}
+//
+// Unmarshal ...
+func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, resp *remoting.Response) 
error {
+       // fix issue https://github.com/apache/dubbo-go/issues/380
+       bufLen := buf.Len()
+       if bufLen < hessian.HEADER_LENGTH {
+               return perrors.WithStack(hessian.ErrHeaderNotEnough)
+       }
+
+       codec := hessian.NewHessianCodec(bufio.NewReaderSize(buf, bufLen))
+
+       // read header
+       err := codec.ReadHeader(&p.Header)
+       if err != nil {
+               return perrors.WithStack(err)
+       }
+
+       if resp != nil { // for client
+               if p.Header.Type&hessian.PackageRequest != 0x00 {
+                       // size of this array must be '7'
+                       // 
https://github.com/apache/dubbo-go-hessian2/blob/master/request.go#L272
+                       p.Body = make([]interface{}, 7)
+               } else {
+                       //pendingRsp, ok := 
client.pendingResponses.Load(SequenceType(p.Header.ID))
+                       //if !ok {
+                       //      return 
perrors.Errorf("client.GetPendingResponse(%v) = nil", p.Header.ID)
+                       //}
+                       p.Body = &hessian.Response{RspObj: resp.Reply}
+               }
+       }
+
+       // read body
+       err = codec.ReadBody(p.Body)
+       return perrors.WithStack(err)
+}
+
+/////////////////////////////////////////
+/////////////////////////////////////////
+
+type DubboCodec struct {
+}
+
+func (c *DubboCodec) EncodeRequest(request remoting.Request) (*bytes.Buffer, 
error) {
+       invocation := request.Data.(invocation.RPCInvocation)
+
+       p := &DubboPackage{}
+       p.Service.Path = invocation.AttachmentsByKey(constant.PATH_KEY, "")
+       p.Service.Interface = 
invocation.AttachmentsByKey(constant.INTERFACE_KEY, "")
+       p.Service.Version = invocation.AttachmentsByKey(constant.VERSION_KEY, 
"")
+       p.Service.Group = invocation.AttachmentsByKey(constant.GROUP_KEY, "")
+       p.Service.Method = invocation.MethodName()
+
+       timeout, err := 
strconv.Atoi(invocation.AttachmentsByKey(constant.TIMEOUT_KEY, "3000"))
+       if err != nil {
+               panic(err)

Review comment:
       重新提交一个,发现分支错了。。




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to