Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refact seri #756

Merged
merged 2 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions protocol/dubbo/dubbo_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ func (c *DubboCodec) Decode(data []byte) (remoting.DecodeResult, int, error) {
return remoting.DecodeResult{}, len, perrors.WithStack(err)
}
return remoting.DecodeResult{IsRequest: true, Result: req}, len, perrors.WithStack(err)
} else {
resp, len, err := c.decodeResponse(data)
if err != nil {
return remoting.DecodeResult{}, len, perrors.WithStack(err)
}
return remoting.DecodeResult{IsRequest: false, Result: resp}, len, perrors.WithStack(err)
}

resp, len, err := c.decodeResponse(data)
if err != nil {
return remoting.DecodeResult{}, len, perrors.WithStack(err)
}
return remoting.DecodeResult{IsRequest: false, Result: resp}, len, perrors.WithStack(err)
}

func (c *DubboCodec) isRequest(data []byte) bool {
Expand Down
18 changes: 8 additions & 10 deletions remoting/getty/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

type (
// GettySessionParam ...
// GettySessionParam is session configuration for getty
GettySessionParam struct {
CompressEncoding bool `default:"false" yaml:"compress_encoding" json:"compress_encoding,omitempty"`
TcpNoDelay bool `default:"true" yaml:"tcp_no_delay" json:"tcp_no_delay,omitempty"`
Expand All @@ -50,8 +50,7 @@ type (
SessionName string `default:"rpc" yaml:"session_name" json:"session_name,omitempty"`
}

// ServerConfig
//Config holds supported types by the multiconfig package
// ServerConfig holds supported types by the multiconfig package
ServerConfig struct {
SSLEnabled bool

Expand All @@ -69,8 +68,7 @@ type (
GettySessionParam GettySessionParam `required:"true" yaml:"getty_session_param" json:"getty_session_param,omitempty"`
}

// ClientConfig
//Config holds supported types by the multiconfig package
// ClientConfig holds supported types by the multiconfig package
ClientConfig struct {
ReconnectInterval int `default:"0" yaml:"reconnect_interval" json:"reconnect_interval,omitempty"`

Expand Down Expand Up @@ -99,7 +97,7 @@ type (
}
)

// GetDefaultClientConfig ...
// GetDefaultClientConfig gets client default configuration
func GetDefaultClientConfig() ClientConfig {
return ClientConfig{
ReconnectInterval: 0,
Expand Down Expand Up @@ -127,7 +125,7 @@ func GetDefaultClientConfig() ClientConfig {
}}
}

// GetDefaultServerConfig ...
// GetDefaultServerConfig gets server default configuration
func GetDefaultServerConfig() ServerConfig {
return ServerConfig{
SessionTimeout: "180s",
Expand All @@ -152,7 +150,7 @@ func GetDefaultServerConfig() ServerConfig {
}
}

// CheckValidity ...
// CheckValidity confirm getty sessian params
func (c *GettySessionParam) CheckValidity() error {
var err error

Expand All @@ -175,7 +173,7 @@ func (c *GettySessionParam) CheckValidity() error {
return nil
}

// CheckValidity ...
// CheckValidity confirm client params.
func (c *ClientConfig) CheckValidity() error {
var err error

Expand All @@ -197,7 +195,7 @@ func (c *ClientConfig) CheckValidity() error {
return perrors.WithStack(c.GettySessionParam.CheckValidity())
}

// CheckValidity ...
// CheckValidity confirm server params
func (c *ServerConfig) CheckValidity() error {
var err error

Expand Down
12 changes: 9 additions & 3 deletions remoting/getty/readwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ import (
// RpcClientPackageHandler
////////////////////////////////////////////

// RpcClientPackageHandler ...
// RpcClientPackageHandler Read data from server and Write data to server
type RpcClientPackageHandler struct {
client *Client
}

// NewRpcClientPackageHandler ...
// NewRpcClientPackageHandler create a RpcClientPackageHandler
func NewRpcClientPackageHandler(client *Client) *RpcClientPackageHandler {
return &RpcClientPackageHandler{client: client}
}

// Read data from server. if the package size from server is larger than 4096 byte, server will read 4096 byte
// and send to client each time. the Read can assemble it.
func (p *RpcClientPackageHandler) Read(ss getty.Session, data []byte) (interface{}, int, error) {
resp, length, err := (p.client.codec).Decode(data)
//err := pkg.Unmarshal(buf, p.client)
Expand All @@ -63,6 +65,7 @@ func (p *RpcClientPackageHandler) Read(ss getty.Session, data []byte) (interface
return resp, length, nil
}

// Write send the data to server
func (p *RpcClientPackageHandler) Write(ss getty.Session, pkg interface{}) ([]byte, error) {
req, ok := pkg.(*remoting.Request)
if !ok {
Expand All @@ -87,7 +90,7 @@ func (p *RpcClientPackageHandler) Write(ss getty.Session, pkg interface{}) ([]by
// rpcServerPkgHandler = &RpcServerPackageHandler{}
//)

// RpcServerPackageHandler ...
// RpcServerPackageHandler Read data from client and Write data to client
type RpcServerPackageHandler struct {
server *Server
}
Expand All @@ -96,6 +99,8 @@ func NewRpcServerPackageHandler(server *Server) *RpcServerPackageHandler {
return &RpcServerPackageHandler{server: server}
}

// Read data from client. if the package size from client is larger than 4096 byte, client will read 4096 byte
// and send to client each time. the Read can assemble it.
func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface{}, int, error) {
req, length, err := (p.server.codec).Decode(data)
//resp,len, err := (*p.).DecodeResponse(buf)
Expand All @@ -113,6 +118,7 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface
return req, length, err
}

// Write send the data to client
func (p *RpcServerPackageHandler) Write(ss getty.Session, pkg interface{}) ([]byte, error) {
res, ok := pkg.(*remoting.Response)
if !ok {
Expand Down