4 Star 5 Fork 4

Plato / Service-Box-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
testcallee_stub.go 9.05 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:52
// source: TestCallee
package testcallee
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 TestCalleeStub struct {
srvImpl ITestCallee
}
func NewTestCalleeStub(srvImpl ITestCallee) *TestCalleeStub {
return &TestCalleeStub{
srvImpl,
}
}
func TestCalleeStubCreator(v interface{}) idlrpc.IStub {
if service, ok := v.(ITestCallee); ok {
return &TestCalleeStub{
service,
}
}
return nil
}
func (sb *TestCalleeStub) GetUUID() idlrpc.SvcUuid {
return SrvUUID
}
func (sb *TestCalleeStub) GetServiceName() string {
return SrvName
}
func (sb *TestCalleeStub) GetSignature(methodId uint32) string {
var sign string
switch methodId {
case 1:
sign = "Add"
case 2:
sign = "Sub"
case 3:
sign = "SubPrivate"
case 4:
sign = "Divide"
}
return sign
}
func (sb *TestCalleeStub) GetMultipleNum() uint32 {
return 0
}
func (sb *TestCalleeStub) OnAfterFork(ctx idlrpc.IServiceContext) bool {
return sb.srvImpl.OnAfterFork(ctx)
}
func (sb *TestCalleeStub) OnTick() bool {
return sb.srvImpl.OnTick()
}
func (sb *TestCalleeStub) OnBeforeDestroy() bool {
return sb.srvImpl.OnBeforeDestroy()
}
func (sb *TestCalleeStub) GetStatus() idlrpc.ServiceStatus {
return idlrpc.SERVICE_RESOLVED
}
func (sb *TestCalleeStub) SetStatus(status idlrpc.ServiceStatus) {
}
func (sb *TestCalleeStub) OnSub(subID string, event string, data []byte) error {
return sb.srvImpl.OnSubscribe(subID, event, data)
}
func (sb *TestCalleeStub) OnCancel(subID string, event string) error {
return sb.srvImpl.OnCancel(subID, event)
}
func (sb *TestCalleeStub) Call(ctx idlrpc.IServiceContext, methodId uint32, req []byte) (resp []byte, err error) {
//解析header
switch methodId {
case 1:
resp, err = sb.Add(ctx, req)
case 2:
resp, err = sb.Sub(ctx, req)
case 3:
resp, err = sb.SubPrivate(ctx, req)
case 4:
resp, err = sb.Divide(ctx, req)
default:
err = errors.New("Method Not Fount!!!!!")
}
return
}
func (sb *TestCalleeStub) Return(ctx idlrpc.IServiceContext, methodIndex uint32, ret interface{}, err error) ([]byte, error) {
var resp []byte
switch methodIndex {
case 1:
if retParam, ok := ret.(int32); ok {
resp, err = sb.doAddReturn(ctx, retParam, err)
} else {
err = errors.New("return Type Not Match")
}
case 2:
if retParam, ok := ret.(int32); ok {
resp, err = sb.doSubReturn(ctx, retParam, err)
} else {
err = errors.New("return Type Not Match")
}
case 3:
if retParam, ok := ret.(int32); ok {
resp, err = sb.doSubPrivateReturn(ctx, retParam, err)
} else {
err = errors.New("return Type Not Match")
}
case 4:
if retParam, ok := ret.(int32); ok {
resp, err = sb.doDivideReturn(ctx, retParam, err)
} else {
err = errors.New("return Type Not Match")
}
}
return resp, err
}
func (sb *TestCalleeStub) GetTimeout(methodIndex uint32) uint32 {
var timeout uint32
switch methodIndex {
case 1:
timeout = 500
case 2:
timeout = 10000
case 3:
timeout = 10000
case 4:
timeout = 10000
}
return timeout
}
func (sb *TestCalleeStub) IsOneWay(methodId uint32) (isOneway bool) {
switch methodId {
case 1:
isOneway = false
case 2:
isOneway = false
case 3:
isOneway = false
case 4:
isOneway = false
default:
isOneway = false
}
return
}
func (sb *TestCalleeStub) Add(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.TestCallee_AddArgs{}
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
_2 := pbReq.Arg2
ret, err := sb.srvImpl.Add(ctx, _1, _2)
if ctx.IsContinue() {
return nil, nil
} else {
return sb.doAddReturn(ctx, ret, err)
}
}
func (sb *TestCalleeStub) doAddReturn(ctx idlrpc.IServiceContext, ret int32, err error) ([]byte, error) {
// 定义返回值 proto 结构体
pbRet := &pbdata.TestCallee_AddRet{}
// 是否有需要返回的上下文
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)
}
func (sb *TestCalleeStub) Sub(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.TestCallee_SubArgs{}
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
_2 := pbReq.Arg2
ret, err := sb.srvImpl.Sub(ctx, _1, _2)
if ctx.IsContinue() {
return nil, nil
} else {
return sb.doSubReturn(ctx, ret, err)
}
}
func (sb *TestCalleeStub) doSubReturn(ctx idlrpc.IServiceContext, ret int32, err error) ([]byte, error) {
// 定义返回值 proto 结构体
pbRet := &pbdata.TestCallee_SubRet{}
// 是否有需要返回的上下文
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)
}
func (sb *TestCalleeStub) SubPrivate(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.TestCallee_SubPrivateArgs{}
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
_2 := pbReq.Arg2
ret, err := sb.srvImpl.SubPrivate(ctx, _1, _2)
if ctx.IsContinue() {
return nil, nil
} else {
return sb.doSubPrivateReturn(ctx, ret, err)
}
}
func (sb *TestCalleeStub) doSubPrivateReturn(ctx idlrpc.IServiceContext, ret int32, err error) ([]byte, error) {
// 定义返回值 proto 结构体
pbRet := &pbdata.TestCallee_SubPrivateRet{}
// 是否有需要返回的上下文
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)
}
func (sb *TestCalleeStub) Divide(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.TestCallee_DivideArgs{}
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
_2 := pbReq.Arg2
ret, err := sb.srvImpl.Divide(ctx, _1, _2)
if ctx.IsContinue() {
return nil, nil
} else {
return sb.doDivideReturn(ctx, ret, err)
}
}
func (sb *TestCalleeStub) doDivideReturn(ctx idlrpc.IServiceContext, ret int32, err error) ([]byte, error) {
// 定义返回值 proto 结构体
pbRet := &pbdata.TestCallee_DivideRet{}
// 是否有需要返回的上下文
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)
}
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.16

搜索帮助

53164aa7 5694891 3bd8fe86 5694891