package bytestreamsplit

import (
	
	
	
)

// This encoder implements a version of the Byte Stream Split encoding as described
// in https://github.com/apache/parquet-format/blob/master/Encodings.md#byte-stream-split-byte_stream_split--9
type Encoding struct {
	encoding.NotSupported
}

func ( *Encoding) () string {
	return "BYTE_STREAM_SPLIT"
}

func ( *Encoding) () format.Encoding {
	return format.ByteStreamSplit
}

func ( *Encoding) ( []byte,  []float32) ([]byte, error) {
	 = resize(, 4*len())
	encodeFloat(, unsafecast.Slice[byte]())
	return , nil
}

func ( *Encoding) ( []byte,  []float64) ([]byte, error) {
	 = resize(, 8*len())
	encodeDouble(, unsafecast.Slice[byte]())
	return , nil
}

func ( *Encoding) ( []float32,  []byte) ([]float32, error) {
	if (len() % 4) != 0 {
		return , encoding.ErrDecodeInvalidInputSize(, "FLOAT", len())
	}
	 := resize(unsafecast.Slice[byte](), len())
	decodeFloat(, )
	return unsafecast.Slice[float32](), nil
}

func ( *Encoding) ( []float64,  []byte) ([]float64, error) {
	if (len() % 8) != 0 {
		return , encoding.ErrDecodeInvalidInputSize(, "DOUBLE", len())
	}
	 := resize(unsafecast.Slice[byte](), len())
	decodeDouble(, )
	return unsafecast.Slice[float64](), nil
}

func resize( []byte,  int) []byte {
	if cap() <  {
		 = make([]byte, , 2*)
	} else {
		 = [:]
	}
	return 
}