github.com/hamba/avro@v1.8.0/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  
     7  	for read < n {
     8  		if r.head == r.tail {
     9  			if !r.loadMore() {
    10  				return
    11  			}
    12  		}
    13  
    14  		if read+r.tail-r.head < n {
    15  			read += r.tail - r.head
    16  			r.head = r.tail
    17  			continue
    18  		}
    19  
    20  		r.head += n - read
    21  		read += n - read
    22  	}
    23  }
    24  
    25  // SkipBool skips a Bool in the reader.
    26  func (r *Reader) SkipBool() {
    27  	_ = r.readByte()
    28  }
    29  
    30  // SkipInt skips an Int in the reader.
    31  func (r *Reader) SkipInt() {
    32  	var offset int8
    33  
    34  	for r.Error == nil {
    35  		if offset == maxIntBufSize {
    36  			return
    37  		}
    38  
    39  		b := r.readByte()
    40  		if b&0x80 == 0 {
    41  			break
    42  		}
    43  
    44  		offset++
    45  	}
    46  }
    47  
    48  // SkipLong skips a Long in the reader.
    49  func (r *Reader) SkipLong() {
    50  	var offset int8
    51  
    52  	for r.Error == nil {
    53  		if offset == maxLongBufSize {
    54  			return
    55  		}
    56  
    57  		b := r.readByte()
    58  		if b&0x80 == 0 {
    59  			break
    60  		}
    61  
    62  		offset++
    63  	}
    64  }
    65  
    66  // SkipFloat skips a Float in the reader.
    67  func (r *Reader) SkipFloat() {
    68  	r.SkipNBytes(4)
    69  }
    70  
    71  // SkipDouble skips a Double in the reader.
    72  func (r *Reader) SkipDouble() {
    73  	r.SkipNBytes(8)
    74  }
    75  
    76  // SkipString skips a String in the reader.
    77  func (r *Reader) SkipString() {
    78  	size := r.ReadLong()
    79  	if size <= 0 {
    80  		return
    81  	}
    82  
    83  	r.SkipNBytes(int(size))
    84  }
    85  
    86  // SkipBytes skips Bytes in the reader.
    87  func (r *Reader) SkipBytes() {
    88  	size := r.ReadLong()
    89  	if size <= 0 {
    90  		return
    91  	}
    92  
    93  	r.SkipNBytes(int(size))
    94  }