Skip to content

Commit

Permalink
Merge pull request #455 from TarsCloud/perf/tars2go
Browse files Browse the repository at this point in the history
perf(protocol): update tars base protocol
  • Loading branch information
lbbniu authored Apr 26, 2023
2 parents e0f508c + 6356844 commit 35ac1fa
Show file tree
Hide file tree
Showing 17 changed files with 614 additions and 3,595 deletions.
188 changes: 24 additions & 164 deletions tars/protocol/res/adminf/AdminF.tars.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package adminf comment
// This file was generated by tars2go 1.1.10
// This file was generated by tars2go 1.2.1
// Generated from AdminF.tars
package adminf

Expand All @@ -14,6 +14,7 @@ import (
"github.com/TarsCloud/TarsGo/tars/protocol/res/requestf"
"github.com/TarsCloud/TarsGo/tars/protocol/tup"
"github.com/TarsCloud/TarsGo/tars/util/current"
"github.com/TarsCloud/TarsGo/tars/util/endpoint"
"github.com/TarsCloud/TarsGo/tars/util/tools"
"unsafe"
)
Expand All @@ -31,56 +32,29 @@ type AdminF struct {
servant m.Servant
}

// Shutdown is the proxy function for the method defined in the tars file, with the context
func (obj *AdminF) Shutdown(opts ...map[string]string) (err error) {
var (
length int32
have bool
ty byte
)
buf := codec.NewBuffer()
// SetServant sets servant for the service.
func (obj *AdminF) SetServant(servant m.Servant) {
obj.servant = servant
}

var statusMap map[string]string
var contextMap map[string]string
if len(opts) == 1 {
contextMap = opts[0]
} else if len(opts) == 2 {
contextMap = opts[0]
statusMap = opts[1]
}
tarsResp := new(requestf.ResponsePacket)
tarsCtx := context.Background()
// TarsSetTimeout sets the timeout for the servant which is in ms.
func (obj *AdminF) TarsSetTimeout(timeout int) {
obj.servant.TarsSetTimeout(timeout)
}

err = obj.servant.TarsInvoke(tarsCtx, 0, "shutdown", buf.ToBytes(), statusMap, contextMap, tarsResp)
if err != nil {
return err
}
// TarsSetProtocol sets the protocol for the servant.
func (obj *AdminF) TarsSetProtocol(p m.Protocol) {
obj.servant.TarsSetProtocol(p)
}

if len(opts) == 1 {
for k := range contextMap {
delete(contextMap, k)
}
for k, v := range tarsResp.Context {
contextMap[k] = v
}
} else if len(opts) == 2 {
for k := range contextMap {
delete(contextMap, k)
}
for k, v := range tarsResp.Context {
contextMap[k] = v
}
for k := range statusMap {
delete(statusMap, k)
}
for k, v := range tarsResp.Status {
statusMap[k] = v
}
}
_ = length
_ = have
_ = ty
return nil
// Endpoints returns all active endpoint.Endpoint
func (obj *AdminF) Endpoints() []*endpoint.Endpoint {
return obj.servant.Endpoints()
}

// Shutdown is the proxy function for the method defined in the tars file, with the context
func (obj *AdminF) Shutdown(opts ...map[string]string) error {
return obj.ShutdownWithContext(context.Background(), opts...)
}

// ShutdownWithContext is the proxy function for the method defined in the tars file, with the context
Expand Down Expand Up @@ -156,93 +130,15 @@ func (obj *AdminF) ShutdownOneWayWithContext(tarsCtx context.Context, opts ...ma
return err
}

if len(opts) == 1 {
for k := range contextMap {
delete(contextMap, k)
}
for k, v := range tarsResp.Context {
contextMap[k] = v
}
} else if len(opts) == 2 {
for k := range contextMap {
delete(contextMap, k)
}
for k, v := range tarsResp.Context {
contextMap[k] = v
}
for k := range statusMap {
delete(statusMap, k)
}
for k, v := range tarsResp.Status {
statusMap[k] = v
}
}
_ = length
_ = have
_ = ty
return nil
}

// Notify is the proxy function for the method defined in the tars file, with the context
func (obj *AdminF) Notify(command string, opts ...map[string]string) (ret string, err error) {
var (
length int32
have bool
ty byte
)
buf := codec.NewBuffer()
err = buf.WriteString(command, 1)
if err != nil {
return ret, err
}

var statusMap map[string]string
var contextMap map[string]string
if len(opts) == 1 {
contextMap = opts[0]
} else if len(opts) == 2 {
contextMap = opts[0]
statusMap = opts[1]
}
tarsResp := new(requestf.ResponsePacket)
tarsCtx := context.Background()

err = obj.servant.TarsInvoke(tarsCtx, 0, "notify", buf.ToBytes(), statusMap, contextMap, tarsResp)
if err != nil {
return ret, err
}

readBuf := codec.NewReader(tools.Int8ToByte(tarsResp.SBuffer))
err = readBuf.ReadString(&ret, 0, true)
if err != nil {
return ret, err
}

if len(opts) == 1 {
for k := range contextMap {
delete(contextMap, k)
}
for k, v := range tarsResp.Context {
contextMap[k] = v
}
} else if len(opts) == 2 {
for k := range contextMap {
delete(contextMap, k)
}
for k, v := range tarsResp.Context {
contextMap[k] = v
}
for k := range statusMap {
delete(statusMap, k)
}
for k, v := range tarsResp.Status {
statusMap[k] = v
}
}
_ = length
_ = have
_ = ty
return ret, nil
func (obj *AdminF) Notify(command string, opts ...map[string]string) (string, error) {
return obj.NotifyWithContext(context.Background(), command, opts...)
}

// NotifyWithContext is the proxy function for the method defined in the tars file, with the context
Expand Down Expand Up @@ -334,48 +230,12 @@ func (obj *AdminF) NotifyOneWayWithContext(tarsCtx context.Context, command stri
return ret, err
}

if len(opts) == 1 {
for k := range contextMap {
delete(contextMap, k)
}
for k, v := range tarsResp.Context {
contextMap[k] = v
}
} else if len(opts) == 2 {
for k := range contextMap {
delete(contextMap, k)
}
for k, v := range tarsResp.Context {
contextMap[k] = v
}
for k := range statusMap {
delete(statusMap, k)
}
for k, v := range tarsResp.Status {
statusMap[k] = v
}
}
_ = length
_ = have
_ = ty
return ret, nil
}

// SetServant sets servant for the service.
func (obj *AdminF) SetServant(servant m.Servant) {
obj.servant = servant
}

// TarsSetTimeout sets the timeout for the servant which is in ms.
func (obj *AdminF) TarsSetTimeout(timeout int) {
obj.servant.TarsSetTimeout(timeout)
}

// TarsSetProtocol sets the protocol for the servant.
func (obj *AdminF) TarsSetProtocol(p m.Protocol) {
obj.servant.TarsSetProtocol(p)
}

type AdminFServant interface {
Shutdown() (err error)
Notify(command string) (ret string, err error)
Expand Down
4 changes: 2 additions & 2 deletions tars/protocol/res/basef/BaseF.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package basef comment
// This file was generated by tars2go 1.1.10
// This file was generated by tars2go 1.2.1
// Generated from BaseF.tars
package basef

Expand All @@ -13,7 +13,7 @@ import (
var _ = fmt.Errorf
var _ = codec.FromInt8

//const as define in tars file
// const as define in tars file
const (
TARSVERSION int16 = 0x01
TUPVERSION int16 = 0x03
Expand Down
Loading

0 comments on commit 35ac1fa

Please sign in to comment.