github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/encoding/delta/byte_array_purego.go (about)

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