()
| 404 | } |
| 405 | |
| 406 | func (r *messageSetReader) readHeader() (err error) { |
| 407 | if r.count > 0 { |
| 408 | // currently reading a set of messages, no need to read a header until they are exhausted. |
| 409 | return |
| 410 | } |
| 411 | r.header = messagesHeader{} |
| 412 | if err = r.readInt64(&r.header.firstOffset); err != nil { |
| 413 | return |
| 414 | } |
| 415 | if err = r.readInt32(&r.header.length); err != nil { |
| 416 | return |
| 417 | } |
| 418 | var crcOrLeaderEpoch int32 |
| 419 | if err = r.readInt32(&crcOrLeaderEpoch); err != nil { |
| 420 | return |
| 421 | } |
| 422 | if err = r.readInt8(&r.header.magic); err != nil { |
| 423 | return |
| 424 | } |
| 425 | switch r.header.magic { |
| 426 | case 0: |
| 427 | r.header.crc = crcOrLeaderEpoch |
| 428 | if err = r.readInt8(&r.header.v1.attributes); err != nil { |
| 429 | return |
| 430 | } |
| 431 | r.count = 1 |
| 432 | // Set arbitrary non-zero length so that we always assume the |
| 433 | // message is truncated since bytes remain. |
| 434 | r.lengthRemain = 1 |
| 435 | if r.debug { |
| 436 | r.log("Read v0 header with offset=%d len=%d magic=%d attributes=%d", r.header.firstOffset, r.header.length, r.header.magic, r.header.v1.attributes) |
| 437 | } |
| 438 | case 1: |
| 439 | r.header.crc = crcOrLeaderEpoch |
| 440 | if err = r.readInt8(&r.header.v1.attributes); err != nil { |
| 441 | return |
| 442 | } |
| 443 | if err = r.readInt64(&r.header.v1.timestamp); err != nil { |
| 444 | return |
| 445 | } |
| 446 | r.count = 1 |
| 447 | // Set arbitrary non-zero length so that we always assume the |
| 448 | // message is truncated since bytes remain. |
| 449 | r.lengthRemain = 1 |
| 450 | if r.debug { |
| 451 | r.log("Read v1 header with remain=%d offset=%d magic=%d and attributes=%d", r.remain, r.header.firstOffset, r.header.magic, r.header.v1.attributes) |
| 452 | } |
| 453 | case 2: |
| 454 | r.header.v2.leaderEpoch = crcOrLeaderEpoch |
| 455 | if err = r.readInt32(&r.header.crc); err != nil { |
| 456 | return |
| 457 | } |
| 458 | if err = r.readInt16(&r.header.v2.attributes); err != nil { |
| 459 | return |
| 460 | } |
| 461 | if err = r.readInt32(&r.header.v2.lastOffsetDelta); err != nil { |
| 462 | return |
| 463 | } |
no test coverage detected