github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/cluster/codecs/Timer.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 Timer struct { 13 CorrelationId int64 14 Deadline int64 15 } 16 17 func (t *Timer) Encode(_m *SbeGoMarshaller, _w io.Writer, doRangeCheck bool) error { 18 if doRangeCheck { 19 if err := t.RangeCheck(t.SbeSchemaVersion(), t.SbeSchemaVersion()); err != nil { 20 return err 21 } 22 } 23 if err := _m.WriteInt64(_w, t.CorrelationId); err != nil { 24 return err 25 } 26 if err := _m.WriteInt64(_w, t.Deadline); err != nil { 27 return err 28 } 29 return nil 30 } 31 32 func (t *Timer) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16, blockLength uint16, doRangeCheck bool) error { 33 if !t.CorrelationIdInActingVersion(actingVersion) { 34 t.CorrelationId = t.CorrelationIdNullValue() 35 } else { 36 if err := _m.ReadInt64(_r, &t.CorrelationId); err != nil { 37 return err 38 } 39 } 40 if !t.DeadlineInActingVersion(actingVersion) { 41 t.Deadline = t.DeadlineNullValue() 42 } else { 43 if err := _m.ReadInt64(_r, &t.Deadline); err != nil { 44 return err 45 } 46 } 47 if actingVersion > t.SbeSchemaVersion() && blockLength > t.SbeBlockLength() { 48 io.CopyN(ioutil.Discard, _r, int64(blockLength-t.SbeBlockLength())) 49 } 50 if doRangeCheck { 51 if err := t.RangeCheck(actingVersion, t.SbeSchemaVersion()); err != nil { 52 return err 53 } 54 } 55 return nil 56 } 57 58 func (t *Timer) RangeCheck(actingVersion uint16, schemaVersion uint16) error { 59 if t.CorrelationIdInActingVersion(actingVersion) { 60 if t.CorrelationId < t.CorrelationIdMinValue() || t.CorrelationId > t.CorrelationIdMaxValue() { 61 return fmt.Errorf("Range check failed on t.CorrelationId (%v < %v > %v)", t.CorrelationIdMinValue(), t.CorrelationId, t.CorrelationIdMaxValue()) 62 } 63 } 64 if t.DeadlineInActingVersion(actingVersion) { 65 if t.Deadline < t.DeadlineMinValue() || t.Deadline > t.DeadlineMaxValue() { 66 return fmt.Errorf("Range check failed on t.Deadline (%v < %v > %v)", t.DeadlineMinValue(), t.Deadline, t.DeadlineMaxValue()) 67 } 68 } 69 return nil 70 } 71 72 func TimerInit(t *Timer) { 73 return 74 } 75 76 func (*Timer) SbeBlockLength() (blockLength uint16) { 77 return 16 78 } 79 80 func (*Timer) SbeTemplateId() (templateId uint16) { 81 return 104 82 } 83 84 func (*Timer) SbeSchemaId() (schemaId uint16) { 85 return 111 86 } 87 88 func (*Timer) SbeSchemaVersion() (schemaVersion uint16) { 89 return 8 90 } 91 92 func (*Timer) SbeSemanticType() (semanticType []byte) { 93 return []byte("") 94 } 95 96 func (*Timer) CorrelationIdId() uint16 { 97 return 1 98 } 99 100 func (*Timer) CorrelationIdSinceVersion() uint16 { 101 return 0 102 } 103 104 func (t *Timer) CorrelationIdInActingVersion(actingVersion uint16) bool { 105 return actingVersion >= t.CorrelationIdSinceVersion() 106 } 107 108 func (*Timer) CorrelationIdDeprecated() uint16 { 109 return 0 110 } 111 112 func (*Timer) CorrelationIdMetaAttribute(meta int) string { 113 switch meta { 114 case 1: 115 return "" 116 case 2: 117 return "" 118 case 3: 119 return "" 120 case 4: 121 return "required" 122 } 123 return "" 124 } 125 126 func (*Timer) CorrelationIdMinValue() int64 { 127 return math.MinInt64 + 1 128 } 129 130 func (*Timer) CorrelationIdMaxValue() int64 { 131 return math.MaxInt64 132 } 133 134 func (*Timer) CorrelationIdNullValue() int64 { 135 return math.MinInt64 136 } 137 138 func (*Timer) DeadlineId() uint16 { 139 return 2 140 } 141 142 func (*Timer) DeadlineSinceVersion() uint16 { 143 return 0 144 } 145 146 func (t *Timer) DeadlineInActingVersion(actingVersion uint16) bool { 147 return actingVersion >= t.DeadlineSinceVersion() 148 } 149 150 func (*Timer) DeadlineDeprecated() uint16 { 151 return 0 152 } 153 154 func (*Timer) DeadlineMetaAttribute(meta int) string { 155 switch meta { 156 case 1: 157 return "" 158 case 2: 159 return "" 160 case 3: 161 return "" 162 case 4: 163 return "required" 164 } 165 return "" 166 } 167 168 func (*Timer) DeadlineMinValue() int64 { 169 return math.MinInt64 + 1 170 } 171 172 func (*Timer) DeadlineMaxValue() int64 { 173 return math.MaxInt64 174 } 175 176 func (*Timer) DeadlineNullValue() int64 { 177 return math.MinInt64 178 }