4 Star 5 Fork 4

Plato / Service-Box-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
testcaller_stub.go 5.43 KB
一键复制 编辑 原始数据 按行查看 历史
CloudGuan 提交于 2023-10-26 02:41 . bug: 更新框架版本
// Machine generated code
// Code generated by go-idl-tool. DO NOT EDIT 2023-02-17 18:48:51
// source: TestCaller
package testcaller
import (
"errors"
"gitee.com/dennis-kk/rpc-go-backend/idlrpc"
"gitee.com/dennis-kk/service-box-go/example/idldata/pbdata"
"google.golang.org/protobuf/proto"
)
type TestCallerStub struct {
srvImpl ITestCaller
}
func NewTestCallerStub(srvImpl ITestCaller) *TestCallerStub {
return &TestCallerStub{
srvImpl,
}
}
func TestCallerStubCreator(v interface{}) idlrpc.IStub {
if service, ok := v.(ITestCaller); ok {
return &TestCallerStub{
service,
}
}
return nil
}
func (sb *TestCallerStub) GetUUID() idlrpc.SvcUuid {
return SrvUUID
}
func (sb *TestCallerStub) GetServiceName() string {
return SrvName
}
func (sb *TestCallerStub) GetSignature(methodId uint32) string {
var sign string
switch methodId {
case 1:
sign = "SetInfo"
case 2:
sign = "GetInfo"
}
return sign
}
func (sb *TestCallerStub) GetMultipleNum() uint32 {
return 0
}
func (sb *TestCallerStub) OnAfterFork(ctx idlrpc.IServiceContext) bool {
return sb.srvImpl.OnAfterFork(ctx)
}
func (sb *TestCallerStub) OnTick() bool {
return sb.srvImpl.OnTick()
}
func (sb *TestCallerStub) OnBeforeDestroy() bool {
return sb.srvImpl.OnBeforeDestroy()
}
func (sb *TestCallerStub) GetStatus() idlrpc.ServiceStatus {
return idlrpc.SERVICE_RESOLVED
}
func (sb *TestCallerStub) SetStatus(status idlrpc.ServiceStatus) {
}
func (sb *TestCallerStub) OnSub(subID string, event string, data []byte) error {
return sb.srvImpl.OnSubscribe(subID, event, data)
}
func (sb *TestCallerStub) OnCancel(subID string, event string) error {
return sb.srvImpl.OnCancel(subID, event)
}
func (sb *TestCallerStub) Call(ctx idlrpc.IServiceContext, methodId uint32, req []byte) (resp []byte, err error) {
//解析header
switch methodId {
case 1:
resp, err = sb.SetInfo(ctx, req)
case 2:
resp, err = sb.GetInfo(ctx, req)
default:
err = errors.New("Method Not Fount!!!!!")
}
return
}
func (sb *TestCallerStub) Return(ctx idlrpc.IServiceContext, methodIndex uint32, ret interface{}, err error) ([]byte, error) {
var resp []byte
switch methodIndex {
case 1:
resp, err = sb.doSetInfoReturn(ctx, err)
case 2:
if retParam, ok := ret.(string); ok {
resp, err = sb.doGetInfoReturn(ctx, retParam, err)
} else {
err = errors.New("return Type Not Match")
}
}
return resp, err
}
func (sb *TestCallerStub) GetTimeout(methodIndex uint32) uint32 {
var timeout uint32
switch methodIndex {
case 1:
timeout = 10000
case 2:
timeout = 10000
}
return timeout
}
func (sb *TestCallerStub) IsOneWay(methodId uint32) (isOneway bool) {
switch methodId {
case 1:
isOneway = false
case 2:
isOneway = false
default:
isOneway = false
}
return
}
func (sb *TestCallerStub) SetInfo(ctx idlrpc.IServiceContext, req []byte) (resp []byte, err error) {
if sb == nil {
err = errors.New(SrvName + "Service is not Register")
return
}
if req == nil {
err = errors.New("request function is invalid")
return
}
//解包协议
pbReq := &pbdata.TestCaller_SetInfoArgs{}
err = proto.Unmarshal(req, pbReq)
if err != nil {
return
}
// 填充context
if pbReq.Ctx != nil && pbReq.Ctx.Info != nil {
for _, kv := range pbReq.Ctx.Info {
ctx.SetContext(kv.Key, kv.Value)
}
}
_1 := pbReq.Arg1
err = sb.srvImpl.SetInfo(ctx, _1)
if ctx.IsContinue() {
return nil, nil
} else {
return sb.doSetInfoReturn(ctx, err)
}
}
func (sb *TestCallerStub) doSetInfoReturn(ctx idlrpc.IServiceContext, err error) ([]byte, error) {
// 定义返回值 proto 结构体
pbRet := &pbdata.TestCaller_SetInfoRet{}
// 是否有需要返回的上下文
kv := ctx.GetResponseContext()
if kv != nil {
if pbRet.Ctx == nil {
pbRet.Ctx = &pbdata.Context{}
}
for k, v := range kv {
pbRet.Ctx.Info = append(pbRet.Ctx.Info, &pbdata.KeyValue{Key: k, Value: v})
}
}
if err != nil {
if pbRet.Ctx == nil {
pbRet.Ctx = &pbdata.Context{}
}
pbRet.Ctx.Info = append(pbRet.Ctx.Info, &pbdata.KeyValue{Key: "error_info", Value: err.Error()})
}
// 序列化返回值
return proto.Marshal(pbRet)
}
func (sb *TestCallerStub) GetInfo(ctx idlrpc.IServiceContext, req []byte) (resp []byte, err error) {
if sb == nil {
err = errors.New(SrvName + "Service is not Register")
return
}
if req == nil {
err = errors.New("request function is invalid")
return
}
//解包协议
pbReq := &pbdata.TestCaller_GetInfoArgs{}
err = proto.Unmarshal(req, pbReq)
if err != nil {
return
}
// 填充context
if pbReq.Ctx != nil && pbReq.Ctx.Info != nil {
for _, kv := range pbReq.Ctx.Info {
ctx.SetContext(kv.Key, kv.Value)
}
}
ret, err := sb.srvImpl.GetInfo(ctx)
if ctx.IsContinue() {
return nil, nil
} else {
return sb.doGetInfoReturn(ctx, ret, err)
}
}
func (sb *TestCallerStub) doGetInfoReturn(ctx idlrpc.IServiceContext, ret string, err error) ([]byte, error) {
// 定义返回值 proto 结构体
pbRet := &pbdata.TestCaller_GetInfoRet{}
// 是否有需要返回的上下文
kv := ctx.GetResponseContext()
if kv != nil {
if pbRet.Ctx == nil {
pbRet.Ctx = &pbdata.Context{}
}
for k, v := range kv {
pbRet.Ctx.Info = append(pbRet.Ctx.Info, &pbdata.KeyValue{Key: k, Value: v})
}
}
//非void 方法,需要构造返回值
pbRet.Ret1 = ret
if err != nil {
if pbRet.Ctx == nil {
pbRet.Ctx = &pbdata.Context{}
}
pbRet.Ctx.Info = append(pbRet.Ctx.Info, &pbdata.KeyValue{Key: "error_info", Value: err.Error()})
}
// 序列化返回值
return proto.Marshal(pbRet)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dennis-kk/service-box-go.git
git@gitee.com:dennis-kk/service-box-go.git
dennis-kk
service-box-go
Service-Box-go
v0.5.17

搜索帮助

344bd9b3 5694891 D2dac590 5694891