github.com/deanMdreon/kafka-go@v0.4.32/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 discardInt8(r *bufio.Reader, sz int) (int, error) { 19 return discardN(r, sz, 1) 20 } 21 22 func discardInt16(r *bufio.Reader, sz int) (int, error) { 23 return discardN(r, sz, 2) 24 } 25 26 func discardInt32(r *bufio.Reader, sz int) (int, error) { 27 return discardN(r, sz, 4) 28 } 29 30 func discardInt64(r *bufio.Reader, sz int) (int, error) { 31 return discardN(r, sz, 8) 32 } 33 34 func discardString(r *bufio.Reader, sz int) (int, error) { 35 return readStringWith(r, sz, func(r *bufio.Reader, sz int, n int) (int, error) { 36 if n < 0 { 37 return sz, nil 38 } 39 return discardN(r, sz, n) 40 }) 41 } 42 43 func discardBytes(r *bufio.Reader, sz int) (int, error) { 44 return readBytesWith(r, sz, func(r *bufio.Reader, sz int, n int) (int, error) { 45 if n < 0 { 46 return sz, nil 47 } 48 return discardN(r, sz, n) 49 }) 50 }