github.com/aacfactory/avro@v1.2.12/internal/base/reader_skip.go (about)

     1  package base
     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 offset int8
    32  	for r.Error == nil {
    33  		if offset == maxIntBufSize {
    34  			return
    35  		}
    36  
    37  		b := r.readByte()
    38  		if b&0x80 == 0 {
    39  			break
    40  		}
    41  		offset++
    42  	}
    43  }
    44  
    45  // SkipLong skips a Long in the reader.
    46  func (r *Reader) SkipLong() {
    47  	var offset int8
    48  	for r.Error == nil {
    49  		if offset == maxLongBufSize {
    50  			return
    51  		}
    52  
    53  		b := r.readByte()
    54  		if b&0x80 == 0 {
    55  			break
    56  		}
    57  		offset++
    58  	}
    59  }
    60  
    61  // SkipFloat skips a Float in the reader.
    62  func (r *Reader) SkipFloat() {
    63  	r.SkipNBytes(4)
    64  }
    65  
    66  // SkipDouble skips a Double in the reader.
    67  func (r *Reader) SkipDouble() {
    68  	r.SkipNBytes(8)
    69  }
    70  
    71  // SkipString skips a String in the reader.
    72  func (r *Reader) SkipString() {
    73  	size := r.ReadLong()
    74  	if size <= 0 {
    75  		return
    76  	}
    77  	r.SkipNBytes(int(size))
    78  }
    79  
    80  // SkipBytes skips Bytes in the reader.
    81  func (r *Reader) SkipBytes() {
    82  	size := r.ReadLong()
    83  	if size <= 0 {
    84  		return
    85  	}
    86  	r.SkipNBytes(int(size))
    87  }