github.com/hamba/avro/v2@v2.22.1-0.20240518180522-aff3955acf7d/reader_skip.go (about)

     1  package avro
     2  
     3  // SkipNBytes skips the given number of bytes in the reader.
     4  func (r *Reader) SkipNBytes(n int) {
     5  	read := 0
     6  	for read < n {
     7  		if r.head == r.tail {
     8  			if !r.loadMore() {
     9  				return
    10  			}
    11  		}
    12  
    13  		if read+r.tail-r.head < n {
    14  			read += r.tail - r.head
    15  			r.head = r.tail
    16  			continue
    17  		}
    18  
    19  		r.head += n - read
    20  		read += n - read
    21  	}
    22  }
    23  
    24  // SkipBool skips a Bool in the reader.
    25  func (r *Reader) SkipBool() {
    26  	_ = r.readByte()
    27  }
    28  
    29  // SkipInt skips an Int in the reader.
    30  func (r *Reader) SkipInt() {
    31  	var n int
    32  	for r.Error == nil && n < maxIntBufSize {
    33  		b := r.readByte()
    34  		if b&0x80 == 0 {
    35  			break
    36  		}
    37  		n++
    38  	}
    39  }
    40  
    41  // SkipLong skips a Long in the reader.
    42  func (r *Reader) SkipLong() {
    43  	var n int
    44  	for r.Error == nil && n < maxLongBufSize {
    45  		b := r.readByte()
    46  		if b&0x80 == 0 {
    47  			break
    48  		}
    49  		n++
    50  	}
    51  }
    52  
    53  // SkipFloat skips a Float in the reader.
    54  func (r *Reader) SkipFloat() {
    55  	r.SkipNBytes(4)
    56  }
    57  
    58  // SkipDouble skips a Double in the reader.
    59  func (r *Reader) SkipDouble() {
    60  	r.SkipNBytes(8)
    61  }
    62  
    63  // SkipString skips a String in the reader.
    64  func (r *Reader) SkipString() {
    65  	size := r.ReadLong()
    66  	if size <= 0 {
    67  		return
    68  	}
    69  	r.SkipNBytes(int(size))
    70  }
    71  
    72  // SkipBytes skips Bytes in the reader.
    73  func (r *Reader) SkipBytes() {
    74  	size := r.ReadLong()
    75  	if size <= 0 {
    76  		return
    77  	}
    78  	r.SkipNBytes(int(size))
    79  }