github.com/streamdal/segmentio-kafka-go@v0.4.47-streamdal/discard.go (about)

     1  package kafka
     2  
     3  import "bufio"
     4  
     5  func discardN(r *bufio.Reader, sz int, n int) (int, error) {
     6  	var err error
     7  	if n <= sz {
     8  		n, err = r.Discard(n)
     9  	} else {
    10  		n, err = r.Discard(sz)
    11  		if err == nil {
    12  			err = errShortRead
    13  		}
    14  	}
    15  	return sz - n, err
    16  }
    17  
    18  func discardInt32(r *bufio.Reader, sz int) (int, error) {
    19  	return discardN(r, sz, 4)
    20  }
    21  
    22  func discardString(r *bufio.Reader, sz int) (int, error) {
    23  	return readStringWith(r, sz, func(r *bufio.Reader, sz int, n int) (int, error) {
    24  		if n < 0 {
    25  			return sz, nil
    26  		}
    27  		return discardN(r, sz, n)
    28  	})
    29  }
    30  
    31  func discardBytes(r *bufio.Reader, sz int) (int, error) {
    32  	return readBytesWith(r, sz, func(r *bufio.Reader, sz int, n int) (int, error) {
    33  		if n < 0 {
    34  			return sz, nil
    35  		}
    36  		return discardN(r, sz, n)
    37  	})
    38  }