-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessage.go
232 lines (197 loc) · 4.52 KB
/
Message.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// Generated SBE (Simple Binary Encoding) message codec
package model
import (
"fmt"
"io"
"io/ioutil"
"math"
)
type Message struct {
MsgId uint64
MsgType uint8
Content []uint8
}
func (m *Message) Encode(_m *SbeGoMarshaller, _w io.Writer, doRangeCheck bool) error {
if doRangeCheck {
if err := m.RangeCheck(m.SbeSchemaVersion(), m.SbeSchemaVersion()); err != nil {
return err
}
}
if err := _m.WriteUint64(_w, m.MsgId); err != nil {
return err
}
if err := _m.WriteUint8(_w, m.MsgType); err != nil {
return err
}
if err := _m.WriteUint32(_w, uint32(len(m.Content))); err != nil {
return err
}
if err := _m.WriteBytes(_w, m.Content); err != nil {
return err
}
return nil
}
func (m *Message) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16, blockLength uint16, doRangeCheck bool) error {
if !m.MsgIdInActingVersion(actingVersion) {
m.MsgId = m.MsgIdNullValue()
} else {
if err := _m.ReadUint64(_r, &m.MsgId); err != nil {
return err
}
}
if !m.MsgTypeInActingVersion(actingVersion) {
m.MsgType = m.MsgTypeNullValue()
} else {
if err := _m.ReadUint8(_r, &m.MsgType); err != nil {
return err
}
}
if actingVersion > m.SbeSchemaVersion() && blockLength > m.SbeBlockLength() {
io.CopyN(ioutil.Discard, _r, int64(blockLength-m.SbeBlockLength()))
}
if m.ContentInActingVersion(actingVersion) {
var ContentLength uint32
if err := _m.ReadUint32(_r, &ContentLength); err != nil {
return err
}
if cap(m.Content) < int(ContentLength) {
m.Content = make([]uint8, ContentLength)
}
if err := _m.ReadBytes(_r, m.Content); err != nil {
return err
}
}
if doRangeCheck {
if err := m.RangeCheck(actingVersion, m.SbeSchemaVersion()); err != nil {
return err
}
}
return nil
}
func (m *Message) RangeCheck(actingVersion uint16, schemaVersion uint16) error {
if m.MsgIdInActingVersion(actingVersion) {
if m.MsgId < m.MsgIdMinValue() || m.MsgId > m.MsgIdMaxValue() {
return fmt.Errorf("Range check failed on m.MsgId (%v < %v > %v)", m.MsgIdMinValue(), m.MsgId, m.MsgIdMaxValue())
}
}
if m.MsgTypeInActingVersion(actingVersion) {
if m.MsgType < m.MsgTypeMinValue() || m.MsgType > m.MsgTypeMaxValue() {
return fmt.Errorf("Range check failed on m.MsgType (%v < %v > %v)", m.MsgTypeMinValue(), m.MsgType, m.MsgTypeMaxValue())
}
}
return nil
}
func MessageInit(m *Message) {
return
}
func (*Message) SbeBlockLength() (blockLength uint16) {
return 9
}
func (*Message) SbeTemplateId() (templateId uint16) {
return 1
}
func (*Message) SbeSchemaId() (schemaId uint16) {
return 0
}
func (*Message) SbeSchemaVersion() (schemaVersion uint16) {
return 0
}
func (*Message) SbeSemanticType() (semanticType []byte) {
return []byte("request")
}
func (*Message) MsgIdId() uint16 {
return 2
}
func (*Message) MsgIdSinceVersion() uint16 {
return 0
}
func (m *Message) MsgIdInActingVersion(actingVersion uint16) bool {
return actingVersion >= m.MsgIdSinceVersion()
}
func (*Message) MsgIdDeprecated() uint16 {
return 0
}
func (*Message) MsgIdMetaAttribute(meta int) string {
switch meta {
case 1:
return ""
case 2:
return ""
case 3:
return ""
case 4:
return "required"
}
return ""
}
func (*Message) MsgIdMinValue() uint64 {
return 0
}
func (*Message) MsgIdMaxValue() uint64 {
return math.MaxUint64 - 1
}
func (*Message) MsgIdNullValue() uint64 {
return math.MaxUint64
}
func (*Message) MsgTypeId() uint16 {
return 3
}
func (*Message) MsgTypeSinceVersion() uint16 {
return 0
}
func (m *Message) MsgTypeInActingVersion(actingVersion uint16) bool {
return actingVersion >= m.MsgTypeSinceVersion()
}
func (*Message) MsgTypeDeprecated() uint16 {
return 0
}
func (*Message) MsgTypeMetaAttribute(meta int) string {
switch meta {
case 1:
return ""
case 2:
return ""
case 3:
return ""
case 4:
return "required"
}
return ""
}
func (*Message) MsgTypeMinValue() uint8 {
return 0
}
func (*Message) MsgTypeMaxValue() uint8 {
return math.MaxUint8 - 1
}
func (*Message) MsgTypeNullValue() uint8 {
return math.MaxUint8
}
func (*Message) ContentMetaAttribute(meta int) string {
switch meta {
case 1:
return "unix"
case 2:
return "nanosecond"
case 3:
return ""
case 4:
return "required"
}
return ""
}
func (*Message) ContentSinceVersion() uint16 {
return 0
}
func (m *Message) ContentInActingVersion(actingVersion uint16) bool {
return actingVersion >= m.ContentSinceVersion()
}
func (*Message) ContentDeprecated() uint16 {
return 0
}
func (Message) ContentCharacterEncoding() string {
return "null"
}
func (Message) ContentHeaderLength() uint64 {
return 4
}