QueryEventParser's Parse processes a raw query event into a QueryEvent.
(raw *RawV4Event)
| 257 | |
| 258 | // QueryEventParser's Parse processes a raw query event into a QueryEvent. |
| 259 | func (p *QueryEventParser) Parse(raw *RawV4Event) (Event, error) { |
| 260 | query := &QueryEvent{ |
| 261 | Event: raw, |
| 262 | } |
| 263 | |
| 264 | type fixedBodyStruct struct { |
| 265 | ThreadId uint32 |
| 266 | Duration uint32 |
| 267 | DatabaseNameLength uint8 |
| 268 | ErrorCode uint16 |
| 269 | StatusLength uint16 |
| 270 | } |
| 271 | |
| 272 | fixed := fixedBodyStruct{} |
| 273 | |
| 274 | _, err := readLittleEndian(raw.FixedLengthData(), &fixed) |
| 275 | if err != nil { |
| 276 | return raw, errors.Wrap(err, "Failed to read fixed body") |
| 277 | } |
| 278 | |
| 279 | query.threadId = fixed.ThreadId |
| 280 | query.duration = fixed.Duration |
| 281 | query.errorCode = mysql_proto.ErrorCode_Type(fixed.ErrorCode) |
| 282 | |
| 283 | data := raw.VariableLengthData() |
| 284 | |
| 285 | dbNameEnd := int(fixed.StatusLength) + int(fixed.DatabaseNameLength) |
| 286 | if dbNameEnd+1 > len(data) { |
| 287 | return raw, errors.Newf("Invalid message length") |
| 288 | } |
| 289 | |
| 290 | query.statusBytes = data[:fixed.StatusLength] |
| 291 | |
| 292 | query.databaseName = data[fixed.StatusLength:dbNameEnd] |
| 293 | |
| 294 | query.query = data[dbNameEnd+1:] |
| 295 | |
| 296 | err = p.parseStatus(query) |
| 297 | if err != nil { |
| 298 | return raw, err |
| 299 | } |
| 300 | |
| 301 | return query, nil |
| 302 | } |
| 303 | |
| 304 | func (p *QueryEventParser) parseStatus(q *QueryEvent) error { |
| 305 | data := q.statusBytes |
nothing calls this directly
no test coverage detected