github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/cluster/codecs/ClusterSession.go (about) 1 // Generated SBE (Simple Binary Encoding) message codec 2 3 package codecs 4 5 import ( 6 "fmt" 7 "io" 8 "io/ioutil" 9 "math" 10 ) 11 12 type ClusterSession struct { 13 ClusterSessionId int64 14 CorrelationId int64 15 OpenedLogPosition int64 16 TimeOfLastActivity int64 17 CloseReason CloseReasonEnum 18 ResponseStreamId int32 19 ResponseChannel []uint8 20 } 21 22 func (c *ClusterSession) Encode(_m *SbeGoMarshaller, _w io.Writer, doRangeCheck bool) error { 23 if doRangeCheck { 24 if err := c.RangeCheck(c.SbeSchemaVersion(), c.SbeSchemaVersion()); err != nil { 25 return err 26 } 27 } 28 if err := _m.WriteInt64(_w, c.ClusterSessionId); err != nil { 29 return err 30 } 31 if err := _m.WriteInt64(_w, c.CorrelationId); err != nil { 32 return err 33 } 34 if err := _m.WriteInt64(_w, c.OpenedLogPosition); err != nil { 35 return err 36 } 37 if err := _m.WriteInt64(_w, c.TimeOfLastActivity); err != nil { 38 return err 39 } 40 if err := c.CloseReason.Encode(_m, _w); err != nil { 41 return err 42 } 43 if err := _m.WriteInt32(_w, c.ResponseStreamId); err != nil { 44 return err 45 } 46 if err := _m.WriteUint32(_w, uint32(len(c.ResponseChannel))); err != nil { 47 return err 48 } 49 if err := _m.WriteBytes(_w, c.ResponseChannel); err != nil { 50 return err 51 } 52 return nil 53 } 54 55 func (c *ClusterSession) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16, blockLength uint16, doRangeCheck bool) error { 56 if !c.ClusterSessionIdInActingVersion(actingVersion) { 57 c.ClusterSessionId = c.ClusterSessionIdNullValue() 58 } else { 59 if err := _m.ReadInt64(_r, &c.ClusterSessionId); err != nil { 60 return err 61 } 62 } 63 if !c.CorrelationIdInActingVersion(actingVersion) { 64 c.CorrelationId = c.CorrelationIdNullValue() 65 } else { 66 if err := _m.ReadInt64(_r, &c.CorrelationId); err != nil { 67 return err 68 } 69 } 70 if !c.OpenedLogPositionInActingVersion(actingVersion) { 71 c.OpenedLogPosition = c.OpenedLogPositionNullValue() 72 } else { 73 if err := _m.ReadInt64(_r, &c.OpenedLogPosition); err != nil { 74 return err 75 } 76 } 77 if !c.TimeOfLastActivityInActingVersion(actingVersion) { 78 c.TimeOfLastActivity = c.TimeOfLastActivityNullValue() 79 } else { 80 if err := _m.ReadInt64(_r, &c.TimeOfLastActivity); err != nil { 81 return err 82 } 83 } 84 if c.CloseReasonInActingVersion(actingVersion) { 85 if err := c.CloseReason.Decode(_m, _r, actingVersion); err != nil { 86 return err 87 } 88 } 89 if !c.ResponseStreamIdInActingVersion(actingVersion) { 90 c.ResponseStreamId = c.ResponseStreamIdNullValue() 91 } else { 92 if err := _m.ReadInt32(_r, &c.ResponseStreamId); err != nil { 93 return err 94 } 95 } 96 if actingVersion > c.SbeSchemaVersion() && blockLength > c.SbeBlockLength() { 97 io.CopyN(ioutil.Discard, _r, int64(blockLength-c.SbeBlockLength())) 98 } 99 100 if c.ResponseChannelInActingVersion(actingVersion) { 101 var ResponseChannelLength uint32 102 if err := _m.ReadUint32(_r, &ResponseChannelLength); err != nil { 103 return err 104 } 105 if cap(c.ResponseChannel) < int(ResponseChannelLength) { 106 c.ResponseChannel = make([]uint8, ResponseChannelLength) 107 } 108 c.ResponseChannel = c.ResponseChannel[:ResponseChannelLength] 109 if err := _m.ReadBytes(_r, c.ResponseChannel); err != nil { 110 return err 111 } 112 } 113 if doRangeCheck { 114 if err := c.RangeCheck(actingVersion, c.SbeSchemaVersion()); err != nil { 115 return err 116 } 117 } 118 return nil 119 } 120 121 func (c *ClusterSession) RangeCheck(actingVersion uint16, schemaVersion uint16) error { 122 if c.ClusterSessionIdInActingVersion(actingVersion) { 123 if c.ClusterSessionId < c.ClusterSessionIdMinValue() || c.ClusterSessionId > c.ClusterSessionIdMaxValue() { 124 return fmt.Errorf("Range check failed on c.ClusterSessionId (%v < %v > %v)", c.ClusterSessionIdMinValue(), c.ClusterSessionId, c.ClusterSessionIdMaxValue()) 125 } 126 } 127 if c.CorrelationIdInActingVersion(actingVersion) { 128 if c.CorrelationId < c.CorrelationIdMinValue() || c.CorrelationId > c.CorrelationIdMaxValue() { 129 return fmt.Errorf("Range check failed on c.CorrelationId (%v < %v > %v)", c.CorrelationIdMinValue(), c.CorrelationId, c.CorrelationIdMaxValue()) 130 } 131 } 132 if c.OpenedLogPositionInActingVersion(actingVersion) { 133 if c.OpenedLogPosition < c.OpenedLogPositionMinValue() || c.OpenedLogPosition > c.OpenedLogPositionMaxValue() { 134 return fmt.Errorf("Range check failed on c.OpenedLogPosition (%v < %v > %v)", c.OpenedLogPositionMinValue(), c.OpenedLogPosition, c.OpenedLogPositionMaxValue()) 135 } 136 } 137 if c.TimeOfLastActivityInActingVersion(actingVersion) { 138 if c.TimeOfLastActivity < c.TimeOfLastActivityMinValue() || c.TimeOfLastActivity > c.TimeOfLastActivityMaxValue() { 139 return fmt.Errorf("Range check failed on c.TimeOfLastActivity (%v < %v > %v)", c.TimeOfLastActivityMinValue(), c.TimeOfLastActivity, c.TimeOfLastActivityMaxValue()) 140 } 141 } 142 if err := c.CloseReason.RangeCheck(actingVersion, schemaVersion); err != nil { 143 return err 144 } 145 if c.ResponseStreamIdInActingVersion(actingVersion) { 146 if c.ResponseStreamId < c.ResponseStreamIdMinValue() || c.ResponseStreamId > c.ResponseStreamIdMaxValue() { 147 return fmt.Errorf("Range check failed on c.ResponseStreamId (%v < %v > %v)", c.ResponseStreamIdMinValue(), c.ResponseStreamId, c.ResponseStreamIdMaxValue()) 148 } 149 } 150 for idx, ch := range c.ResponseChannel { 151 if ch > 127 { 152 return fmt.Errorf("c.ResponseChannel[%d]=%d failed ASCII validation", idx, ch) 153 } 154 } 155 return nil 156 } 157 158 func ClusterSessionInit(c *ClusterSession) { 159 return 160 } 161 162 func (*ClusterSession) SbeBlockLength() (blockLength uint16) { 163 return 40 164 } 165 166 func (*ClusterSession) SbeTemplateId() (templateId uint16) { 167 return 103 168 } 169 170 func (*ClusterSession) SbeSchemaId() (schemaId uint16) { 171 return 111 172 } 173 174 func (*ClusterSession) SbeSchemaVersion() (schemaVersion uint16) { 175 return 8 176 } 177 178 func (*ClusterSession) SbeSemanticType() (semanticType []byte) { 179 return []byte("") 180 } 181 182 func (*ClusterSession) ClusterSessionIdId() uint16 { 183 return 1 184 } 185 186 func (*ClusterSession) ClusterSessionIdSinceVersion() uint16 { 187 return 0 188 } 189 190 func (c *ClusterSession) ClusterSessionIdInActingVersion(actingVersion uint16) bool { 191 return actingVersion >= c.ClusterSessionIdSinceVersion() 192 } 193 194 func (*ClusterSession) ClusterSessionIdDeprecated() uint16 { 195 return 0 196 } 197 198 func (*ClusterSession) ClusterSessionIdMetaAttribute(meta int) string { 199 switch meta { 200 case 1: 201 return "" 202 case 2: 203 return "" 204 case 3: 205 return "" 206 case 4: 207 return "required" 208 } 209 return "" 210 } 211 212 func (*ClusterSession) ClusterSessionIdMinValue() int64 { 213 return math.MinInt64 + 1 214 } 215 216 func (*ClusterSession) ClusterSessionIdMaxValue() int64 { 217 return math.MaxInt64 218 } 219 220 func (*ClusterSession) ClusterSessionIdNullValue() int64 { 221 return math.MinInt64 222 } 223 224 func (*ClusterSession) CorrelationIdId() uint16 { 225 return 2 226 } 227 228 func (*ClusterSession) CorrelationIdSinceVersion() uint16 { 229 return 0 230 } 231 232 func (c *ClusterSession) CorrelationIdInActingVersion(actingVersion uint16) bool { 233 return actingVersion >= c.CorrelationIdSinceVersion() 234 } 235 236 func (*ClusterSession) CorrelationIdDeprecated() uint16 { 237 return 0 238 } 239 240 func (*ClusterSession) CorrelationIdMetaAttribute(meta int) string { 241 switch meta { 242 case 1: 243 return "" 244 case 2: 245 return "" 246 case 3: 247 return "" 248 case 4: 249 return "required" 250 } 251 return "" 252 } 253 254 func (*ClusterSession) CorrelationIdMinValue() int64 { 255 return math.MinInt64 + 1 256 } 257 258 func (*ClusterSession) CorrelationIdMaxValue() int64 { 259 return math.MaxInt64 260 } 261 262 func (*ClusterSession) CorrelationIdNullValue() int64 { 263 return math.MinInt64 264 } 265 266 func (*ClusterSession) OpenedLogPositionId() uint16 { 267 return 3 268 } 269 270 func (*ClusterSession) OpenedLogPositionSinceVersion() uint16 { 271 return 0 272 } 273 274 func (c *ClusterSession) OpenedLogPositionInActingVersion(actingVersion uint16) bool { 275 return actingVersion >= c.OpenedLogPositionSinceVersion() 276 } 277 278 func (*ClusterSession) OpenedLogPositionDeprecated() uint16 { 279 return 0 280 } 281 282 func (*ClusterSession) OpenedLogPositionMetaAttribute(meta int) string { 283 switch meta { 284 case 1: 285 return "" 286 case 2: 287 return "" 288 case 3: 289 return "" 290 case 4: 291 return "required" 292 } 293 return "" 294 } 295 296 func (*ClusterSession) OpenedLogPositionMinValue() int64 { 297 return math.MinInt64 + 1 298 } 299 300 func (*ClusterSession) OpenedLogPositionMaxValue() int64 { 301 return math.MaxInt64 302 } 303 304 func (*ClusterSession) OpenedLogPositionNullValue() int64 { 305 return math.MinInt64 306 } 307 308 func (*ClusterSession) TimeOfLastActivityId() uint16 { 309 return 4 310 } 311 312 func (*ClusterSession) TimeOfLastActivitySinceVersion() uint16 { 313 return 0 314 } 315 316 func (c *ClusterSession) TimeOfLastActivityInActingVersion(actingVersion uint16) bool { 317 return actingVersion >= c.TimeOfLastActivitySinceVersion() 318 } 319 320 func (*ClusterSession) TimeOfLastActivityDeprecated() uint16 { 321 return 0 322 } 323 324 func (*ClusterSession) TimeOfLastActivityMetaAttribute(meta int) string { 325 switch meta { 326 case 1: 327 return "" 328 case 2: 329 return "" 330 case 3: 331 return "" 332 case 4: 333 return "required" 334 } 335 return "" 336 } 337 338 func (*ClusterSession) TimeOfLastActivityMinValue() int64 { 339 return math.MinInt64 + 1 340 } 341 342 func (*ClusterSession) TimeOfLastActivityMaxValue() int64 { 343 return math.MaxInt64 344 } 345 346 func (*ClusterSession) TimeOfLastActivityNullValue() int64 { 347 return math.MinInt64 348 } 349 350 func (*ClusterSession) CloseReasonId() uint16 { 351 return 5 352 } 353 354 func (*ClusterSession) CloseReasonSinceVersion() uint16 { 355 return 0 356 } 357 358 func (c *ClusterSession) CloseReasonInActingVersion(actingVersion uint16) bool { 359 return actingVersion >= c.CloseReasonSinceVersion() 360 } 361 362 func (*ClusterSession) CloseReasonDeprecated() uint16 { 363 return 0 364 } 365 366 func (*ClusterSession) CloseReasonMetaAttribute(meta int) string { 367 switch meta { 368 case 1: 369 return "" 370 case 2: 371 return "" 372 case 3: 373 return "" 374 case 4: 375 return "required" 376 } 377 return "" 378 } 379 380 func (*ClusterSession) ResponseStreamIdId() uint16 { 381 return 6 382 } 383 384 func (*ClusterSession) ResponseStreamIdSinceVersion() uint16 { 385 return 0 386 } 387 388 func (c *ClusterSession) ResponseStreamIdInActingVersion(actingVersion uint16) bool { 389 return actingVersion >= c.ResponseStreamIdSinceVersion() 390 } 391 392 func (*ClusterSession) ResponseStreamIdDeprecated() uint16 { 393 return 0 394 } 395 396 func (*ClusterSession) ResponseStreamIdMetaAttribute(meta int) string { 397 switch meta { 398 case 1: 399 return "" 400 case 2: 401 return "" 402 case 3: 403 return "" 404 case 4: 405 return "required" 406 } 407 return "" 408 } 409 410 func (*ClusterSession) ResponseStreamIdMinValue() int32 { 411 return math.MinInt32 + 1 412 } 413 414 func (*ClusterSession) ResponseStreamIdMaxValue() int32 { 415 return math.MaxInt32 416 } 417 418 func (*ClusterSession) ResponseStreamIdNullValue() int32 { 419 return math.MinInt32 420 } 421 422 func (*ClusterSession) ResponseChannelMetaAttribute(meta int) string { 423 switch meta { 424 case 1: 425 return "" 426 case 2: 427 return "" 428 case 3: 429 return "" 430 case 4: 431 return "required" 432 } 433 return "" 434 } 435 436 func (*ClusterSession) ResponseChannelSinceVersion() uint16 { 437 return 0 438 } 439 440 func (c *ClusterSession) ResponseChannelInActingVersion(actingVersion uint16) bool { 441 return actingVersion >= c.ResponseChannelSinceVersion() 442 } 443 444 func (*ClusterSession) ResponseChannelDeprecated() uint16 { 445 return 0 446 } 447 448 func (ClusterSession) ResponseChannelCharacterEncoding() string { 449 return "US-ASCII" 450 } 451 452 func (ClusterSession) ResponseChannelHeaderLength() uint64 { 453 return 4 454 }