nextBlock returns the next block. If an error occurs d.err will be set. Optionally the function can block for new output. If non-blocking mode is used the returned boolean will be false if no data was available without blocking.
(blocking bool)
| 415 | // If non-blocking mode is used the returned boolean will be false |
| 416 | // if no data was available without blocking. |
| 417 | func (d *Decoder) nextBlock(blocking bool) (ok bool) { |
| 418 | if d.current.err != nil { |
| 419 | // Keep error state. |
| 420 | return false |
| 421 | } |
| 422 | d.current.b = d.current.b[:0] |
| 423 | |
| 424 | // SYNC: |
| 425 | if d.syncStream.enabled { |
| 426 | if !blocking { |
| 427 | return false |
| 428 | } |
| 429 | ok = d.nextBlockSync() |
| 430 | if !ok { |
| 431 | d.stashDecoder() |
| 432 | } |
| 433 | return ok |
| 434 | } |
| 435 | |
| 436 | //ASYNC: |
| 437 | d.stashDecoder() |
| 438 | if blocking { |
| 439 | d.current.decodeOutput, ok = <-d.current.output |
| 440 | } else { |
| 441 | select { |
| 442 | case d.current.decodeOutput, ok = <-d.current.output: |
| 443 | default: |
| 444 | return false |
| 445 | } |
| 446 | } |
| 447 | if !ok { |
| 448 | // This should not happen, so signal error state... |
| 449 | d.current.err = io.ErrUnexpectedEOF |
| 450 | return false |
| 451 | } |
| 452 | next := d.current.decodeOutput |
| 453 | if next.d != nil && next.d.async.newHist != nil { |
| 454 | d.current.crc.Reset() |
| 455 | } |
| 456 | if debugDecoder { |
| 457 | var tmp [4]byte |
| 458 | binary.LittleEndian.PutUint32(tmp[:], uint32(xxhash.Sum64(next.b))) |
| 459 | println("got", len(d.current.b), "bytes, error:", d.current.err, "data crc:", tmp) |
| 460 | } |
| 461 | |
| 462 | if d.o.ignoreChecksum { |
| 463 | return true |
| 464 | } |
| 465 | |
| 466 | if len(next.b) > 0 { |
| 467 | d.current.crc.Write(next.b) |
| 468 | } |
| 469 | if next.err == nil && next.d != nil && next.d.hasCRC { |
| 470 | got := uint32(d.current.crc.Sum64()) |
| 471 | if got != next.d.checkCRC { |
| 472 | if debugDecoder { |
| 473 | printf("CRC Check Failed: %08x (got) != %08x (on stream)\n", got, next.d.checkCRC) |
| 474 | } |
no test coverage detected