github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/cluster/codecs/TimerEvent.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 TimerEvent struct { 13 LeadershipTermId int64 14 CorrelationId int64 15 Timestamp int64 16 } 17 18 func (t *TimerEvent) Encode(_m *SbeGoMarshaller, _w io.Writer, doRangeCheck bool) error { 19 if doRangeCheck { 20 if err := t.RangeCheck(t.SbeSchemaVersion(), t.SbeSchemaVersion()); err != nil { 21 return err 22 } 23 } 24 if err := _m.WriteInt64(_w, t.LeadershipTermId); err != nil { 25 return err 26 } 27 if err := _m.WriteInt64(_w, t.CorrelationId); err != nil { 28 return err 29 } 30 if err := _m.WriteInt64(_w, t.Timestamp); err != nil { 31 return err 32 } 33 return nil 34 } 35 36 func (t *TimerEvent) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16, blockLength uint16, doRangeCheck bool) error { 37 if !t.LeadershipTermIdInActingVersion(actingVersion) { 38 t.LeadershipTermId = t.LeadershipTermIdNullValue() 39 } else { 40 if err := _m.ReadInt64(_r, &t.LeadershipTermId); err != nil { 41 return err 42 } 43 } 44 if !t.CorrelationIdInActingVersion(actingVersion) { 45 t.CorrelationId = t.CorrelationIdNullValue() 46 } else { 47 if err := _m.ReadInt64(_r, &t.CorrelationId); err != nil { 48 return err 49 } 50 } 51 if !t.TimestampInActingVersion(actingVersion) { 52 t.Timestamp = t.TimestampNullValue() 53 } else { 54 if err := _m.ReadInt64(_r, &t.Timestamp); err != nil { 55 return err 56 } 57 } 58 if actingVersion > t.SbeSchemaVersion() && blockLength > t.SbeBlockLength() { 59 io.CopyN(ioutil.Discard, _r, int64(blockLength-t.SbeBlockLength())) 60 } 61 if doRangeCheck { 62 if err := t.RangeCheck(actingVersion, t.SbeSchemaVersion()); err != nil { 63 return err 64 } 65 } 66 return nil 67 } 68 69 func (t *TimerEvent) RangeCheck(actingVersion uint16, schemaVersion uint16) error { 70 if t.LeadershipTermIdInActingVersion(actingVersion) { 71 if t.LeadershipTermId < t.LeadershipTermIdMinValue() || t.LeadershipTermId > t.LeadershipTermIdMaxValue() { 72 return fmt.Errorf("Range check failed on t.LeadershipTermId (%v < %v > %v)", t.LeadershipTermIdMinValue(), t.LeadershipTermId, t.LeadershipTermIdMaxValue()) 73 } 74 } 75 if t.CorrelationIdInActingVersion(actingVersion) { 76 if t.CorrelationId < t.CorrelationIdMinValue() || t.CorrelationId > t.CorrelationIdMaxValue() { 77 return fmt.Errorf("Range check failed on t.CorrelationId (%v < %v > %v)", t.CorrelationIdMinValue(), t.CorrelationId, t.CorrelationIdMaxValue()) 78 } 79 } 80 if t.TimestampInActingVersion(actingVersion) { 81 if t.Timestamp < t.TimestampMinValue() || t.Timestamp > t.TimestampMaxValue() { 82 return fmt.Errorf("Range check failed on t.Timestamp (%v < %v > %v)", t.TimestampMinValue(), t.Timestamp, t.TimestampMaxValue()) 83 } 84 } 85 return nil 86 } 87 88 func TimerEventInit(t *TimerEvent) { 89 return 90 } 91 92 func (*TimerEvent) SbeBlockLength() (blockLength uint16) { 93 return 24 94 } 95 96 func (*TimerEvent) SbeTemplateId() (templateId uint16) { 97 return 20 98 } 99 100 func (*TimerEvent) SbeSchemaId() (schemaId uint16) { 101 return 111 102 } 103 104 func (*TimerEvent) SbeSchemaVersion() (schemaVersion uint16) { 105 return 8 106 } 107 108 func (*TimerEvent) SbeSemanticType() (semanticType []byte) { 109 return []byte("") 110 } 111 112 func (*TimerEvent) LeadershipTermIdId() uint16 { 113 return 1 114 } 115 116 func (*TimerEvent) LeadershipTermIdSinceVersion() uint16 { 117 return 0 118 } 119 120 func (t *TimerEvent) LeadershipTermIdInActingVersion(actingVersion uint16) bool { 121 return actingVersion >= t.LeadershipTermIdSinceVersion() 122 } 123 124 func (*TimerEvent) LeadershipTermIdDeprecated() uint16 { 125 return 0 126 } 127 128 func (*TimerEvent) LeadershipTermIdMetaAttribute(meta int) string { 129 switch meta { 130 case 1: 131 return "" 132 case 2: 133 return "" 134 case 3: 135 return "" 136 case 4: 137 return "required" 138 } 139 return "" 140 } 141 142 func (*TimerEvent) LeadershipTermIdMinValue() int64 { 143 return math.MinInt64 + 1 144 } 145 146 func (*TimerEvent) LeadershipTermIdMaxValue() int64 { 147 return math.MaxInt64 148 } 149 150 func (*TimerEvent) LeadershipTermIdNullValue() int64 { 151 return math.MinInt64 152 } 153 154 func (*TimerEvent) CorrelationIdId() uint16 { 155 return 2 156 } 157 158 func (*TimerEvent) CorrelationIdSinceVersion() uint16 { 159 return 0 160 } 161 162 func (t *TimerEvent) CorrelationIdInActingVersion(actingVersion uint16) bool { 163 return actingVersion >= t.CorrelationIdSinceVersion() 164 } 165 166 func (*TimerEvent) CorrelationIdDeprecated() uint16 { 167 return 0 168 } 169 170 func (*TimerEvent) CorrelationIdMetaAttribute(meta int) string { 171 switch meta { 172 case 1: 173 return "" 174 case 2: 175 return "" 176 case 3: 177 return "" 178 case 4: 179 return "required" 180 } 181 return "" 182 } 183 184 func (*TimerEvent) CorrelationIdMinValue() int64 { 185 return math.MinInt64 + 1 186 } 187 188 func (*TimerEvent) CorrelationIdMaxValue() int64 { 189 return math.MaxInt64 190 } 191 192 func (*TimerEvent) CorrelationIdNullValue() int64 { 193 return math.MinInt64 194 } 195 196 func (*TimerEvent) TimestampId() uint16 { 197 return 3 198 } 199 200 func (*TimerEvent) TimestampSinceVersion() uint16 { 201 return 0 202 } 203 204 func (t *TimerEvent) TimestampInActingVersion(actingVersion uint16) bool { 205 return actingVersion >= t.TimestampSinceVersion() 206 } 207 208 func (*TimerEvent) TimestampDeprecated() uint16 { 209 return 0 210 } 211 212 func (*TimerEvent) TimestampMetaAttribute(meta int) string { 213 switch meta { 214 case 1: 215 return "" 216 case 2: 217 return "" 218 case 3: 219 return "" 220 case 4: 221 return "required" 222 } 223 return "" 224 } 225 226 func (*TimerEvent) TimestampMinValue() int64 { 227 return math.MinInt64 + 1 228 } 229 230 func (*TimerEvent) TimestampMaxValue() int64 { 231 return math.MaxInt64 232 } 233 234 func (*TimerEvent) TimestampNullValue() int64 { 235 return math.MinInt64 236 }