github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/iterator_raw.go (about)

     1  package jzon
     2  
     3  // SkipRaw skips and returns the bytes skipped
     4  // slice will not be copied, so make a copy if the return
     5  // value is to be stored somewhere
     6  func (it *Iterator) SkipRaw() ([]byte, error) {
     7  	c, err := it.nextToken()
     8  	if err != nil {
     9  		return nil, err
    10  	}
    11  	oldCapture := it.capture
    12  	it.capture = true
    13  	begin := it.head
    14  	it.head++
    15  	err = skipFunctions[c](it, c)
    16  	it.capture = oldCapture
    17  	if err != nil {
    18  		return nil, err
    19  	}
    20  	return it.buffer[begin:it.head], nil
    21  }
    22  
    23  // AppendRaw is like SkipRaw but it is a copy version
    24  func (it *Iterator) AppendRaw(in []byte) ([]byte, error) {
    25  	b, err := it.SkipRaw()
    26  	if err != nil {
    27  		return in, err
    28  	}
    29  	// https://github.com/go101/go101/wiki
    30  	return append(in, b...), nil
    31  }
    32  
    33  // ReadRaw reads a raw json object (slice will be copied)
    34  func (it *Iterator) ReadRaw() ([]byte, error) {
    35  	return it.AppendRaw(nil)
    36  }