MCPcopy Create free account
hub / github.com/buger/jsonparser / readMore

Method readMore

reader_parser.go:622–671  ·  view source on GitHub ↗

SYS-REQ-116

()

Source from the content-addressed store, hash-verified

620
621// SYS-REQ-116
622func (rp *ReaderParser) readMore() error {
623 if rp.readErr != nil {
624 return rp.readErr
625 }
626 if rp.reader == nil {
627 rp.readErr = io.EOF
628 return rp.readErr
629 }
630
631 readSize := defaultReaderBufferSize
632 maxBufferSize := rp.config.MaxBufferSize
633 if maxBufferSize <= 0 {
634 maxBufferSize = defaultReaderMaxBufferSize
635 }
636 if readSize > maxBufferSize {
637 readSize = maxBufferSize
638 }
639 if readSize < 1 {
640 readSize = 1
641 }
642
643 oldLen := len(rp.buf)
644 if cap(rp.buf)-oldLen < readSize {
645 grown := make([]byte, oldLen, oldLen+readSize)
646 copy(grown, rp.buf)
647 rp.buf = grown
648 }
649 rp.buf = rp.buf[:oldLen+readSize]
650 n, err := rp.reader.Read(rp.buf[oldLen:])
651 rp.buf = rp.buf[:oldLen+n]
652
653 if n > 0 {
654 rp.emptyReads = 0
655 if err != nil {
656 rp.readErr = err
657 }
658 return nil
659 }
660 if err != nil {
661 rp.readErr = err
662 return err
663 }
664
665 rp.emptyReads++
666 if rp.emptyReads >= maxConsecutiveEmptyReads {
667 rp.readErr = io.ErrNoProgress
668 return rp.readErr
669 }
670 return nil
671}
672
673// SYS-REQ-116
674func (rp *ReaderParser) discardConsumed() {

Callers 1

peekByteMethod · 0.95

Calls 1

ReadMethod · 0.45

Tested by

no test coverage detected