github.com/parquet-go/parquet-go@v0.21.1-0.20240501160520-b3c3a0c3ed6f/encoding/delta/byte_array_purego.go (about)

     1  //go:build purego || !amd64
     2  
     3  package delta
     4  
     5  func decodeByteArray(dst, src []byte, prefix, suffix []int32, offsets []uint32) ([]byte, []uint32, error) {
     6  	_ = prefix[:len(suffix)]
     7  	_ = suffix[:len(prefix)]
     8  
     9  	var lastValue []byte
    10  	for i := range suffix {
    11  		n := int(suffix[i])
    12  		p := int(prefix[i])
    13  		if n < 0 {
    14  			return dst, offsets, errInvalidNegativeValueLength(n)
    15  		}
    16  		if n > len(src) {
    17  			return dst, offsets, errValueLengthOutOfBounds(n, len(src))
    18  		}
    19  		if p < 0 {
    20  			return dst, offsets, errInvalidNegativePrefixLength(p)
    21  		}
    22  		if p > len(lastValue) {
    23  			return dst, offsets, errPrefixLengthOutOfBounds(p, len(lastValue))
    24  		}
    25  		j := len(dst)
    26  		offsets = append(offsets, uint32(j))
    27  		dst = append(dst, lastValue[:p]...)
    28  		dst = append(dst, src[:n]...)
    29  		lastValue = dst[j:]
    30  		src = src[n:]
    31  	}
    32  
    33  	return dst, append(offsets, uint32(len(dst))), nil
    34  }
    35  
    36  func decodeFixedLenByteArray(dst, src []byte, size int, prefix, suffix []int32) ([]byte, error) {
    37  	_ = prefix[:len(suffix)]
    38  	_ = suffix[:len(prefix)]
    39  
    40  	var lastValue []byte
    41  	for i := range suffix {
    42  		n := int(suffix[i])
    43  		p := int(prefix[i])
    44  		if n < 0 {
    45  			return dst, errInvalidNegativeValueLength(n)
    46  		}
    47  		if n > len(src) {
    48  			return dst, errValueLengthOutOfBounds(n, len(src))
    49  		}
    50  		if p < 0 {
    51  			return dst, errInvalidNegativePrefixLength(p)
    52  		}
    53  		if p > len(lastValue) {
    54  			return dst, errPrefixLengthOutOfBounds(p, len(lastValue))
    55  		}
    56  		j := len(dst)
    57  		dst = append(dst, lastValue[:p]...)
    58  		dst = append(dst, src[:n]...)
    59  		lastValue = dst[j:]
    60  		src = src[n:]
    61  	}
    62  	return dst, nil
    63  }