Skip to content

Commit 6356844

Browse files
committed
perf(protocol): update tars base protocol
1 parent 079a222 commit 6356844

File tree

17 files changed

+614
-3595
lines changed

17 files changed

+614
-3595
lines changed

tars/protocol/res/adminf/AdminF.tars.go

+24-164
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Package adminf comment
2-
// This file was generated by tars2go 1.1.10
2+
// This file was generated by tars2go 1.2.1
33
// Generated from AdminF.tars
44
package adminf
55

@@ -14,6 +14,7 @@ import (
1414
"github.com/TarsCloud/TarsGo/tars/protocol/res/requestf"
1515
"github.com/TarsCloud/TarsGo/tars/protocol/tup"
1616
"github.com/TarsCloud/TarsGo/tars/util/current"
17+
"github.com/TarsCloud/TarsGo/tars/util/endpoint"
1718
"github.com/TarsCloud/TarsGo/tars/util/tools"
1819
"unsafe"
1920
)
@@ -31,56 +32,29 @@ type AdminF struct {
3132
servant m.Servant
3233
}
3334

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

43-
var statusMap map[string]string
44-
var contextMap map[string]string
45-
if len(opts) == 1 {
46-
contextMap = opts[0]
47-
} else if len(opts) == 2 {
48-
contextMap = opts[0]
49-
statusMap = opts[1]
50-
}
51-
tarsResp := new(requestf.ResponsePacket)
52-
tarsCtx := context.Background()
40+
// TarsSetTimeout sets the timeout for the servant which is in ms.
41+
func (obj *AdminF) TarsSetTimeout(timeout int) {
42+
obj.servant.TarsSetTimeout(timeout)
43+
}
5344

54-
err = obj.servant.TarsInvoke(tarsCtx, 0, "shutdown", buf.ToBytes(), statusMap, contextMap, tarsResp)
55-
if err != nil {
56-
return err
57-
}
45+
// TarsSetProtocol sets the protocol for the servant.
46+
func (obj *AdminF) TarsSetProtocol(p m.Protocol) {
47+
obj.servant.TarsSetProtocol(p)
48+
}
5849

59-
if len(opts) == 1 {
60-
for k := range contextMap {
61-
delete(contextMap, k)
62-
}
63-
for k, v := range tarsResp.Context {
64-
contextMap[k] = v
65-
}
66-
} else if len(opts) == 2 {
67-
for k := range contextMap {
68-
delete(contextMap, k)
69-
}
70-
for k, v := range tarsResp.Context {
71-
contextMap[k] = v
72-
}
73-
for k := range statusMap {
74-
delete(statusMap, k)
75-
}
76-
for k, v := range tarsResp.Status {
77-
statusMap[k] = v
78-
}
79-
}
80-
_ = length
81-
_ = have
82-
_ = ty
83-
return nil
50+
// Endpoints returns all active endpoint.Endpoint
51+
func (obj *AdminF) Endpoints() []*endpoint.Endpoint {
52+
return obj.servant.Endpoints()
53+
}
54+
55+
// Shutdown is the proxy function for the method defined in the tars file, with the context
56+
func (obj *AdminF) Shutdown(opts ...map[string]string) error {
57+
return obj.ShutdownWithContext(context.Background(), opts...)
8458
}
8559

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

159-
if len(opts) == 1 {
160-
for k := range contextMap {
161-
delete(contextMap, k)
162-
}
163-
for k, v := range tarsResp.Context {
164-
contextMap[k] = v
165-
}
166-
} else if len(opts) == 2 {
167-
for k := range contextMap {
168-
delete(contextMap, k)
169-
}
170-
for k, v := range tarsResp.Context {
171-
contextMap[k] = v
172-
}
173-
for k := range statusMap {
174-
delete(statusMap, k)
175-
}
176-
for k, v := range tarsResp.Status {
177-
statusMap[k] = v
178-
}
179-
}
180133
_ = length
181134
_ = have
182135
_ = ty
183136
return nil
184137
}
185138

186139
// Notify is the proxy function for the method defined in the tars file, with the context
187-
func (obj *AdminF) Notify(command string, opts ...map[string]string) (ret string, err error) {
188-
var (
189-
length int32
190-
have bool
191-
ty byte
192-
)
193-
buf := codec.NewBuffer()
194-
err = buf.WriteString(command, 1)
195-
if err != nil {
196-
return ret, err
197-
}
198-
199-
var statusMap map[string]string
200-
var contextMap map[string]string
201-
if len(opts) == 1 {
202-
contextMap = opts[0]
203-
} else if len(opts) == 2 {
204-
contextMap = opts[0]
205-
statusMap = opts[1]
206-
}
207-
tarsResp := new(requestf.ResponsePacket)
208-
tarsCtx := context.Background()
209-
210-
err = obj.servant.TarsInvoke(tarsCtx, 0, "notify", buf.ToBytes(), statusMap, contextMap, tarsResp)
211-
if err != nil {
212-
return ret, err
213-
}
214-
215-
readBuf := codec.NewReader(tools.Int8ToByte(tarsResp.SBuffer))
216-
err = readBuf.ReadString(&ret, 0, true)
217-
if err != nil {
218-
return ret, err
219-
}
220-
221-
if len(opts) == 1 {
222-
for k := range contextMap {
223-
delete(contextMap, k)
224-
}
225-
for k, v := range tarsResp.Context {
226-
contextMap[k] = v
227-
}
228-
} else if len(opts) == 2 {
229-
for k := range contextMap {
230-
delete(contextMap, k)
231-
}
232-
for k, v := range tarsResp.Context {
233-
contextMap[k] = v
234-
}
235-
for k := range statusMap {
236-
delete(statusMap, k)
237-
}
238-
for k, v := range tarsResp.Status {
239-
statusMap[k] = v
240-
}
241-
}
242-
_ = length
243-
_ = have
244-
_ = ty
245-
return ret, nil
140+
func (obj *AdminF) Notify(command string, opts ...map[string]string) (string, error) {
141+
return obj.NotifyWithContext(context.Background(), command, opts...)
246142
}
247143

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

337-
if len(opts) == 1 {
338-
for k := range contextMap {
339-
delete(contextMap, k)
340-
}
341-
for k, v := range tarsResp.Context {
342-
contextMap[k] = v
343-
}
344-
} else if len(opts) == 2 {
345-
for k := range contextMap {
346-
delete(contextMap, k)
347-
}
348-
for k, v := range tarsResp.Context {
349-
contextMap[k] = v
350-
}
351-
for k := range statusMap {
352-
delete(statusMap, k)
353-
}
354-
for k, v := range tarsResp.Status {
355-
statusMap[k] = v
356-
}
357-
}
358233
_ = length
359234
_ = have
360235
_ = ty
361236
return ret, nil
362237
}
363238

364-
// SetServant sets servant for the service.
365-
func (obj *AdminF) SetServant(servant m.Servant) {
366-
obj.servant = servant
367-
}
368-
369-
// TarsSetTimeout sets the timeout for the servant which is in ms.
370-
func (obj *AdminF) TarsSetTimeout(timeout int) {
371-
obj.servant.TarsSetTimeout(timeout)
372-
}
373-
374-
// TarsSetProtocol sets the protocol for the servant.
375-
func (obj *AdminF) TarsSetProtocol(p m.Protocol) {
376-
obj.servant.TarsSetProtocol(p)
377-
}
378-
379239
type AdminFServant interface {
380240
Shutdown() (err error)
381241
Notify(command string) (ret string, err error)

tars/protocol/res/basef/BaseF.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Package basef comment
2-
// This file was generated by tars2go 1.1.10
2+
// This file was generated by tars2go 1.2.1
33
// Generated from BaseF.tars
44
package basef
55

@@ -13,7 +13,7 @@ import (
1313
var _ = fmt.Errorf
1414
var _ = codec.FromInt8
1515

16-
//const as define in tars file
16+
// const as define in tars file
1717
const (
1818
TARSVERSION int16 = 0x01
1919
TUPVERSION int16 = 0x03

0 commit comments

Comments
 (0)