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