github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/cluster/codecs/SnapshotMarker.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 SnapshotMarker struct { 13 TypeId int64 14 LogPosition int64 15 LeadershipTermId int64 16 Index int32 17 Mark SnapshotMarkEnum 18 TimeUnit ClusterTimeUnitEnum 19 AppVersion int32 20 } 21 22 func (s *SnapshotMarker) Encode(_m *SbeGoMarshaller, _w io.Writer, doRangeCheck bool) error { 23 if doRangeCheck { 24 if err := s.RangeCheck(s.SbeSchemaVersion(), s.SbeSchemaVersion()); err != nil { 25 return err 26 } 27 } 28 if err := _m.WriteInt64(_w, s.TypeId); err != nil { 29 return err 30 } 31 if err := _m.WriteInt64(_w, s.LogPosition); err != nil { 32 return err 33 } 34 if err := _m.WriteInt64(_w, s.LeadershipTermId); err != nil { 35 return err 36 } 37 if err := _m.WriteInt32(_w, s.Index); err != nil { 38 return err 39 } 40 if err := s.Mark.Encode(_m, _w); err != nil { 41 return err 42 } 43 if err := s.TimeUnit.Encode(_m, _w); err != nil { 44 return err 45 } 46 if err := _m.WriteInt32(_w, s.AppVersion); err != nil { 47 return err 48 } 49 return nil 50 } 51 52 func (s *SnapshotMarker) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16, blockLength uint16, doRangeCheck bool) error { 53 if !s.TypeIdInActingVersion(actingVersion) { 54 s.TypeId = s.TypeIdNullValue() 55 } else { 56 if err := _m.ReadInt64(_r, &s.TypeId); err != nil { 57 return err 58 } 59 } 60 if !s.LogPositionInActingVersion(actingVersion) { 61 s.LogPosition = s.LogPositionNullValue() 62 } else { 63 if err := _m.ReadInt64(_r, &s.LogPosition); err != nil { 64 return err 65 } 66 } 67 if !s.LeadershipTermIdInActingVersion(actingVersion) { 68 s.LeadershipTermId = s.LeadershipTermIdNullValue() 69 } else { 70 if err := _m.ReadInt64(_r, &s.LeadershipTermId); err != nil { 71 return err 72 } 73 } 74 if !s.IndexInActingVersion(actingVersion) { 75 s.Index = s.IndexNullValue() 76 } else { 77 if err := _m.ReadInt32(_r, &s.Index); err != nil { 78 return err 79 } 80 } 81 if s.MarkInActingVersion(actingVersion) { 82 if err := s.Mark.Decode(_m, _r, actingVersion); err != nil { 83 return err 84 } 85 } 86 if s.TimeUnitInActingVersion(actingVersion) { 87 if err := s.TimeUnit.Decode(_m, _r, actingVersion); err != nil { 88 return err 89 } 90 } 91 if !s.AppVersionInActingVersion(actingVersion) { 92 s.AppVersion = s.AppVersionNullValue() 93 } else { 94 if err := _m.ReadInt32(_r, &s.AppVersion); err != nil { 95 return err 96 } 97 } 98 if actingVersion > s.SbeSchemaVersion() && blockLength > s.SbeBlockLength() { 99 io.CopyN(ioutil.Discard, _r, int64(blockLength-s.SbeBlockLength())) 100 } 101 if doRangeCheck { 102 if err := s.RangeCheck(actingVersion, s.SbeSchemaVersion()); err != nil { 103 return err 104 } 105 } 106 return nil 107 } 108 109 func (s *SnapshotMarker) RangeCheck(actingVersion uint16, schemaVersion uint16) error { 110 if s.TypeIdInActingVersion(actingVersion) { 111 if s.TypeId < s.TypeIdMinValue() || s.TypeId > s.TypeIdMaxValue() { 112 return fmt.Errorf("Range check failed on s.TypeId (%v < %v > %v)", s.TypeIdMinValue(), s.TypeId, s.TypeIdMaxValue()) 113 } 114 } 115 if s.LogPositionInActingVersion(actingVersion) { 116 if s.LogPosition < s.LogPositionMinValue() || s.LogPosition > s.LogPositionMaxValue() { 117 return fmt.Errorf("Range check failed on s.LogPosition (%v < %v > %v)", s.LogPositionMinValue(), s.LogPosition, s.LogPositionMaxValue()) 118 } 119 } 120 if s.LeadershipTermIdInActingVersion(actingVersion) { 121 if s.LeadershipTermId < s.LeadershipTermIdMinValue() || s.LeadershipTermId > s.LeadershipTermIdMaxValue() { 122 return fmt.Errorf("Range check failed on s.LeadershipTermId (%v < %v > %v)", s.LeadershipTermIdMinValue(), s.LeadershipTermId, s.LeadershipTermIdMaxValue()) 123 } 124 } 125 if s.IndexInActingVersion(actingVersion) { 126 if s.Index < s.IndexMinValue() || s.Index > s.IndexMaxValue() { 127 return fmt.Errorf("Range check failed on s.Index (%v < %v > %v)", s.IndexMinValue(), s.Index, s.IndexMaxValue()) 128 } 129 } 130 if err := s.Mark.RangeCheck(actingVersion, schemaVersion); err != nil { 131 return err 132 } 133 if err := s.TimeUnit.RangeCheck(actingVersion, schemaVersion); err != nil { 134 return err 135 } 136 if s.AppVersionInActingVersion(actingVersion) { 137 if s.AppVersion != s.AppVersionNullValue() && (s.AppVersion < s.AppVersionMinValue() || s.AppVersion > s.AppVersionMaxValue()) { 138 return fmt.Errorf("Range check failed on s.AppVersion (%v < %v > %v)", s.AppVersionMinValue(), s.AppVersion, s.AppVersionMaxValue()) 139 } 140 } 141 return nil 142 } 143 144 func SnapshotMarkerInit(s *SnapshotMarker) { 145 s.AppVersion = 0 146 return 147 } 148 149 func (*SnapshotMarker) SbeBlockLength() (blockLength uint16) { 150 return 40 151 } 152 153 func (*SnapshotMarker) SbeTemplateId() (templateId uint16) { 154 return 100 155 } 156 157 func (*SnapshotMarker) SbeSchemaId() (schemaId uint16) { 158 return 111 159 } 160 161 func (*SnapshotMarker) SbeSchemaVersion() (schemaVersion uint16) { 162 return 8 163 } 164 165 func (*SnapshotMarker) SbeSemanticType() (semanticType []byte) { 166 return []byte("") 167 } 168 169 func (*SnapshotMarker) TypeIdId() uint16 { 170 return 1 171 } 172 173 func (*SnapshotMarker) TypeIdSinceVersion() uint16 { 174 return 0 175 } 176 177 func (s *SnapshotMarker) TypeIdInActingVersion(actingVersion uint16) bool { 178 return actingVersion >= s.TypeIdSinceVersion() 179 } 180 181 func (*SnapshotMarker) TypeIdDeprecated() uint16 { 182 return 0 183 } 184 185 func (*SnapshotMarker) TypeIdMetaAttribute(meta int) string { 186 switch meta { 187 case 1: 188 return "" 189 case 2: 190 return "" 191 case 3: 192 return "" 193 case 4: 194 return "required" 195 } 196 return "" 197 } 198 199 func (*SnapshotMarker) TypeIdMinValue() int64 { 200 return math.MinInt64 + 1 201 } 202 203 func (*SnapshotMarker) TypeIdMaxValue() int64 { 204 return math.MaxInt64 205 } 206 207 func (*SnapshotMarker) TypeIdNullValue() int64 { 208 return math.MinInt64 209 } 210 211 func (*SnapshotMarker) LogPositionId() uint16 { 212 return 2 213 } 214 215 func (*SnapshotMarker) LogPositionSinceVersion() uint16 { 216 return 0 217 } 218 219 func (s *SnapshotMarker) LogPositionInActingVersion(actingVersion uint16) bool { 220 return actingVersion >= s.LogPositionSinceVersion() 221 } 222 223 func (*SnapshotMarker) LogPositionDeprecated() uint16 { 224 return 0 225 } 226 227 func (*SnapshotMarker) LogPositionMetaAttribute(meta int) string { 228 switch meta { 229 case 1: 230 return "" 231 case 2: 232 return "" 233 case 3: 234 return "" 235 case 4: 236 return "required" 237 } 238 return "" 239 } 240 241 func (*SnapshotMarker) LogPositionMinValue() int64 { 242 return math.MinInt64 + 1 243 } 244 245 func (*SnapshotMarker) LogPositionMaxValue() int64 { 246 return math.MaxInt64 247 } 248 249 func (*SnapshotMarker) LogPositionNullValue() int64 { 250 return math.MinInt64 251 } 252 253 func (*SnapshotMarker) LeadershipTermIdId() uint16 { 254 return 3 255 } 256 257 func (*SnapshotMarker) LeadershipTermIdSinceVersion() uint16 { 258 return 0 259 } 260 261 func (s *SnapshotMarker) LeadershipTermIdInActingVersion(actingVersion uint16) bool { 262 return actingVersion >= s.LeadershipTermIdSinceVersion() 263 } 264 265 func (*SnapshotMarker) LeadershipTermIdDeprecated() uint16 { 266 return 0 267 } 268 269 func (*SnapshotMarker) LeadershipTermIdMetaAttribute(meta int) string { 270 switch meta { 271 case 1: 272 return "" 273 case 2: 274 return "" 275 case 3: 276 return "" 277 case 4: 278 return "required" 279 } 280 return "" 281 } 282 283 func (*SnapshotMarker) LeadershipTermIdMinValue() int64 { 284 return math.MinInt64 + 1 285 } 286 287 func (*SnapshotMarker) LeadershipTermIdMaxValue() int64 { 288 return math.MaxInt64 289 } 290 291 func (*SnapshotMarker) LeadershipTermIdNullValue() int64 { 292 return math.MinInt64 293 } 294 295 func (*SnapshotMarker) IndexId() uint16 { 296 return 4 297 } 298 299 func (*SnapshotMarker) IndexSinceVersion() uint16 { 300 return 0 301 } 302 303 func (s *SnapshotMarker) IndexInActingVersion(actingVersion uint16) bool { 304 return actingVersion >= s.IndexSinceVersion() 305 } 306 307 func (*SnapshotMarker) IndexDeprecated() uint16 { 308 return 0 309 } 310 311 func (*SnapshotMarker) IndexMetaAttribute(meta int) string { 312 switch meta { 313 case 1: 314 return "" 315 case 2: 316 return "" 317 case 3: 318 return "" 319 case 4: 320 return "required" 321 } 322 return "" 323 } 324 325 func (*SnapshotMarker) IndexMinValue() int32 { 326 return math.MinInt32 + 1 327 } 328 329 func (*SnapshotMarker) IndexMaxValue() int32 { 330 return math.MaxInt32 331 } 332 333 func (*SnapshotMarker) IndexNullValue() int32 { 334 return math.MinInt32 335 } 336 337 func (*SnapshotMarker) MarkId() uint16 { 338 return 5 339 } 340 341 func (*SnapshotMarker) MarkSinceVersion() uint16 { 342 return 0 343 } 344 345 func (s *SnapshotMarker) MarkInActingVersion(actingVersion uint16) bool { 346 return actingVersion >= s.MarkSinceVersion() 347 } 348 349 func (*SnapshotMarker) MarkDeprecated() uint16 { 350 return 0 351 } 352 353 func (*SnapshotMarker) MarkMetaAttribute(meta int) string { 354 switch meta { 355 case 1: 356 return "" 357 case 2: 358 return "" 359 case 3: 360 return "" 361 case 4: 362 return "required" 363 } 364 return "" 365 } 366 367 func (*SnapshotMarker) TimeUnitId() uint16 { 368 return 6 369 } 370 371 func (*SnapshotMarker) TimeUnitSinceVersion() uint16 { 372 return 4 373 } 374 375 func (s *SnapshotMarker) TimeUnitInActingVersion(actingVersion uint16) bool { 376 return actingVersion >= s.TimeUnitSinceVersion() 377 } 378 379 func (*SnapshotMarker) TimeUnitDeprecated() uint16 { 380 return 0 381 } 382 383 func (*SnapshotMarker) TimeUnitMetaAttribute(meta int) string { 384 switch meta { 385 case 1: 386 return "" 387 case 2: 388 return "" 389 case 3: 390 return "" 391 case 4: 392 return "optional" 393 } 394 return "" 395 } 396 397 func (*SnapshotMarker) AppVersionId() uint16 { 398 return 7 399 } 400 401 func (*SnapshotMarker) AppVersionSinceVersion() uint16 { 402 return 4 403 } 404 405 func (s *SnapshotMarker) AppVersionInActingVersion(actingVersion uint16) bool { 406 return actingVersion >= s.AppVersionSinceVersion() 407 } 408 409 func (*SnapshotMarker) AppVersionDeprecated() uint16 { 410 return 0 411 } 412 413 func (*SnapshotMarker) AppVersionMetaAttribute(meta int) string { 414 switch meta { 415 case 1: 416 return "" 417 case 2: 418 return "" 419 case 3: 420 return "" 421 case 4: 422 return "optional" 423 } 424 return "" 425 } 426 427 func (*SnapshotMarker) AppVersionMinValue() int32 { 428 return 1 429 } 430 431 func (*SnapshotMarker) AppVersionMaxValue() int32 { 432 return 16777215 433 } 434 435 func (*SnapshotMarker) AppVersionNullValue() int32 { 436 return 0 437 }