修复RPC同时兼容json与pb的一些bug

This commit is contained in:
boyce
2020-10-27 17:00:15 +08:00
parent 11cb070da2
commit 1d2c1bb7ad
5 changed files with 13 additions and 5 deletions

View File

@@ -226,7 +226,7 @@ func (slf *Client) RawGo(processor IRpcProcessor,noReply bool,serviceMethod stri
return call return call
} }
err = slf.conn.WriteMsg(bytes) err = slf.conn.WriteMsg([]byte{uint8(processor.GetProcessorType())},bytes)
if err != nil { if err != nil {
slf.RemovePending(call.Seq) slf.RemovePending(call.Seq)
call.Err = err call.Err = err

View File

@@ -87,6 +87,11 @@ func (slf *JsonProcessor) IsParse(param interface{}) bool {
} }
func (slf *JsonProcessor) GetProcessorType() RpcProcessorType{
return RPC_PROCESSOR_JSON
}
func (slf *JsonRpcRequestData) IsNoReply() bool{ func (slf *JsonRpcRequestData) IsNoReply() bool{
return slf.NoReply return slf.NoReply
} }
@@ -132,5 +137,3 @@ func (slf *JsonRpcResponseData) GetReply() []byte{

View File

@@ -134,6 +134,11 @@ func (slf *PBProcessor) IsParse(param interface{}) bool {
} }
func (slf *PBProcessor) GetProcessorType() RpcProcessorType{
return RPC_PROCESSOR_PB
}
func (slf *PBRpcRequestData) IsNoReply() bool{ func (slf *PBRpcRequestData) IsNoReply() bool{
return slf.GetNoReply() return slf.GetNoReply()
} }

View File

@@ -9,6 +9,7 @@ type IRpcProcessor interface {
ReleaseRpcRequest(rpcRequestData IRpcRequestData) ReleaseRpcRequest(rpcRequestData IRpcRequestData)
ReleaseRpcRespose(rpcRequestData IRpcResponseData) ReleaseRpcRespose(rpcRequestData IRpcResponseData)
IsParse(param interface{}) bool //是否可解析 IsParse(param interface{}) bool //是否可解析
GetProcessorType() RpcProcessorType
} }

View File

@@ -108,8 +108,7 @@ func (agent *RpcAgent) WriteRespone(processor IRpcProcessor,serviceMethod string
return return
} }
errM = agent.conn.WriteMsg([]byte{uint8(processor.GetProcessorType())},bytes)
errM = agent.conn.WriteMsg(bytes)
if errM != nil { if errM != nil {
log.Error("Rpc %s return is error:%+v",serviceMethod,errM) log.Error("Rpc %s return is error:%+v",serviceMethod,errM)
} }