-
Notifications
You must be signed in to change notification settings - Fork 508
/
NodeF.go
140 lines (116 loc) · 2.4 KB
/
NodeF.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Package nodef comment
// This file was generated by tars2go 1.1.7
// Generated from NodeF.tars
package nodef
import (
"fmt"
"github.com/TarsCloud/TarsGo/tars/protocol/codec"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = fmt.Errorf
var _ = codec.FromInt8
// ServerInfo struct implement
type ServerInfo struct {
Application string `json:"application"`
ServerName string `json:"serverName"`
Pid int32 `json:"pid"`
Adapter string `json:"adapter"`
}
func (st *ServerInfo) ResetDefault() {
}
// ReadFrom reads from readBuf and put into struct.
func (st *ServerInfo) ReadFrom(readBuf *codec.Reader) error {
var (
err error
length int32
have bool
ty byte
)
st.ResetDefault()
err = readBuf.ReadString(&st.Application, 0, true)
if err != nil {
return err
}
err = readBuf.ReadString(&st.ServerName, 1, true)
if err != nil {
return err
}
err = readBuf.ReadInt32(&st.Pid, 2, true)
if err != nil {
return err
}
err = readBuf.ReadString(&st.Adapter, 3, false)
if err != nil {
return err
}
_ = err
_ = length
_ = have
_ = ty
return nil
}
// ReadBlock reads struct from the given tag , require or optional.
func (st *ServerInfo) ReadBlock(readBuf *codec.Reader, tag byte, require bool) error {
var (
err error
have bool
)
st.ResetDefault()
have, err = readBuf.SkipTo(codec.StructBegin, tag, require)
if err != nil {
return err
}
if !have {
if require {
return fmt.Errorf("require ServerInfo, but not exist. tag %d", tag)
}
return nil
}
err = st.ReadFrom(readBuf)
if err != nil {
return err
}
err = readBuf.SkipToStructEnd()
if err != nil {
return err
}
_ = have
return nil
}
// WriteTo encode struct to buffer
func (st *ServerInfo) WriteTo(buf *codec.Buffer) (err error) {
err = buf.WriteString(st.Application, 0)
if err != nil {
return err
}
err = buf.WriteString(st.ServerName, 1)
if err != nil {
return err
}
err = buf.WriteInt32(st.Pid, 2)
if err != nil {
return err
}
err = buf.WriteString(st.Adapter, 3)
if err != nil {
return err
}
return err
}
// WriteBlock encode struct
func (st *ServerInfo) WriteBlock(buf *codec.Buffer, tag byte) error {
var err error
err = buf.WriteHead(codec.StructBegin, tag)
if err != nil {
return err
}
err = st.WriteTo(buf)
if err != nil {
return err
}
err = buf.WriteHead(codec.StructEnd, 0)
if err != nil {
return err
}
return nil
}