MCPcopy
hub / github.com/dropbox/godropbox / Parse

Method Parse

database/binlog/query_event.go:259–302  ·  view source on GitHub ↗

QueryEventParser's Parse processes a raw query event into a QueryEvent.

(raw *RawV4Event)

Source from the content-addressed store, hash-verified

257
258// QueryEventParser's Parse processes a raw query event into a QueryEvent.
259func (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
304func (p *QueryEventParser) parseStatus(q *QueryEvent) error {
305 data := q.statusBytes

Callers

nothing calls this directly

Calls 6

parseStatusMethod · 0.95
WrapFunction · 0.92
NewfFunction · 0.92
readLittleEndianFunction · 0.85
FixedLengthDataMethod · 0.65
VariableLengthDataMethod · 0.65

Tested by

no test coverage detected