github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/aeron/driver/flyweights.go (about) 1 /* 2 Copyright 2016-2018 Stanislav Liberman 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package driver 18 19 import ( 20 "github.com/lirm/aeron-go/aeron/atomic" 21 "github.com/lirm/aeron-go/aeron/flyweight" 22 ) 23 24 /** 25 * Control message flyweight for any errors sent from driver to clients 26 * 27 * <p> 28 * 0 1 2 3 29 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 30 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 31 * | Offending Command Correlation ID | 32 * | | 33 * +---------------------------------------------------------------+ 34 * | Error Code | 35 * +---------------------------------------------------------------+ 36 * | Error Message Length | 37 * +---------------------------------------------------------------+ 38 * | Error Message ... 39 * ... | 40 * +---------------------------------------------------------------+ 41 */ 42 type errorMessage struct { 43 flyweight.FWBase 44 45 offendingCommandCorrelationID flyweight.Int64Field 46 errorCode flyweight.Int32Field 47 errorMessage flyweight.StringField 48 } 49 50 func (m *errorMessage) Wrap(buf *atomic.Buffer, offset int) flyweight.Flyweight { 51 pos := offset 52 pos += m.offendingCommandCorrelationID.Wrap(buf, pos) 53 pos += m.errorCode.Wrap(buf, pos) 54 pos += m.errorMessage.Wrap(buf, pos, m, true) 55 56 m.SetSize(pos - offset) 57 return m 58 } 59 60 /** 61 * Message to denote that new buffers have been added for a publication. 62 * 63 * @see ControlProtocolEvents 64 * 65 * 0 1 2 3 66 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 67 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 68 * | Correlation ID | 69 * | | 70 * +---------------------------------------------------------------+ 71 * | Registration ID | 72 * | | 73 * +---------------------------------------------------------------+ 74 * | Session ID | 75 * +---------------------------------------------------------------+ 76 * | Stream ID | 77 * +---------------------------------------------------------------+ 78 * | Position Limit Counter Id | 79 * +---------------------------------------------------------------+ 80 * | Channel Status Indicator ID | 81 * +---------------------------------------------------------------+ 82 * | Log File Length | 83 * +---------------------------------------------------------------+ 84 * | Log File Name ... 85 * ... | 86 * +---------------------------------------------------------------+ 87 */ 88 type publicationReady struct { 89 flyweight.FWBase 90 91 correlationID flyweight.Int64Field 92 registrationID flyweight.Int64Field 93 sessionID flyweight.Int32Field 94 streamID flyweight.Int32Field 95 publicationLimitOffset flyweight.Int32Field 96 channelStatusIndicatorID flyweight.Int32Field 97 logFileName flyweight.StringField 98 } 99 100 func (m *publicationReady) Wrap(buf *atomic.Buffer, offset int) flyweight.Flyweight { 101 pos := offset 102 pos += m.correlationID.Wrap(buf, pos) 103 pos += m.registrationID.Wrap(buf, pos) 104 pos += m.sessionID.Wrap(buf, pos) 105 pos += m.streamID.Wrap(buf, pos) 106 pos += m.publicationLimitOffset.Wrap(buf, pos) 107 pos += m.channelStatusIndicatorID.Wrap(buf, pos) 108 pos += m.logFileName.Wrap(buf, pos, m, true) 109 110 m.SetSize(pos - offset) 111 return m 112 } 113 114 /** 115 * Message to denote that a Subscription has been successfully set up. 116 * 117 * 0 1 2 3 118 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 119 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 120 * | Correlation ID | 121 * | | 122 * +---------------------------------------------------------------+ 123 * | Channel Status Indicator ID | 124 * +---------------------------------------------------------------+ 125 */ 126 type subscriptionReady struct { 127 flyweight.FWBase 128 129 correlationID flyweight.Int64Field 130 channelStatusIndicatorID flyweight.Int32Field 131 } 132 133 func (m *subscriptionReady) Wrap(buf *atomic.Buffer, offset int) flyweight.Flyweight { 134 pos := offset 135 pos += m.correlationID.Wrap(buf, pos) 136 pos += m.channelStatusIndicatorID.Wrap(buf, pos) 137 138 m.SetSize(pos - offset) 139 return m 140 } 141 142 /** 143 * Message to denote that new buffers have been added for a subscription. 144 * 145 * NOTE: Layout should be SBE compliant 146 * 147 * @see ControlProtocolEvents 148 * 149 * 0 1 2 3 150 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 151 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 152 * | Correlation ID | 153 * | | 154 * +---------------------------------------------------------------+ 155 * | Session ID | 156 * +---------------------------------------------------------------+ 157 * | Stream ID | 158 * +---------------------------------------------------------------+ 159 * | Subscriber Registration Id | 160 * | | 161 * +---------------------------------------------------------------+ 162 * | Subscriber Position Id | 163 * +---------------------------------------------------------------+ 164 * | Log File Length | 165 * +---------------------------------------------------------------+ 166 * | Log File Name ... 167 *... | 168 * +---------------------------------------------------------------+ 169 * | Source identity Length | 170 * +---------------------------------------------------------------+ 171 * | Source identity Name ... 172 *... | 173 * +---------------------------------------------------------------+ 174 */ 175 type imageReadyHeader struct { 176 flyweight.FWBase 177 178 correlationID flyweight.Int64Field 179 sessionID flyweight.Int32Field 180 streamID flyweight.Int32Field 181 subsRegistrationID flyweight.Int64Field 182 subsPosID flyweight.Int32Field 183 logFile flyweight.StringField 184 sourceIdentity flyweight.StringField 185 } 186 187 func (m *imageReadyHeader) Wrap(buf *atomic.Buffer, offset int) flyweight.Flyweight { 188 pos := offset 189 pos += m.correlationID.Wrap(buf, pos) 190 pos += m.sessionID.Wrap(buf, pos) 191 pos += m.streamID.Wrap(buf, pos) 192 pos += m.subsRegistrationID.Wrap(buf, pos) 193 pos += m.subsPosID.Wrap(buf, pos) 194 pos += m.logFile.Wrap(buf, pos, m, true) 195 pos += m.sourceIdentity.Wrap(buf, pos, m, true) 196 197 m.SetSize(pos - offset) 198 return m 199 } 200 201 /** 202 * Message to denote that a Counter has been successfully set up or removed. 203 * 204 * 0 1 2 3 205 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 206 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 207 * | Correlation ID | 208 * | | 209 * +---------------------------------------------------------------+ 210 * | Counter ID | 211 * +---------------------------------------------------------------+ 212 */ 213 type counterUpdate struct { 214 flyweight.FWBase 215 216 correlationID flyweight.Int64Field 217 counterID flyweight.Int32Field 218 } 219 220 func (m *counterUpdate) Wrap(buf *atomic.Buffer, offset int) flyweight.Flyweight { 221 pos := offset 222 pos += m.correlationID.Wrap(buf, pos) 223 pos += m.counterID.Wrap(buf, pos) 224 225 m.SetSize(pos - offset) 226 return m 227 } 228 229 /** 230 * Indicate a client has timed out by the driver. 231 * 232 * 0 1 2 3 233 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 234 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 235 * | Client Id | 236 * | | 237 * +---------------------------------------------------------------+ 238 */ 239 type clientTimeout struct { 240 flyweight.FWBase 241 242 clientID flyweight.Int64Field 243 } 244 245 func (m *clientTimeout) Wrap(buf *atomic.Buffer, offset int) flyweight.Flyweight { 246 pos := offset 247 pos += m.clientID.Wrap(buf, pos) 248 249 m.SetSize(pos - offset) 250 return m 251 }