github.com/parquet-go/parquet-go@v0.21.1-0.20240501160520-b3c3a0c3ed6f/encoding/encoding.go (about) 1 // Package encoding provides the generic APIs implemented by parquet encodings 2 // in its sub-packages. 3 package encoding 4 5 import ( 6 "math" 7 8 "github.com/parquet-go/parquet-go/deprecated" 9 "github.com/parquet-go/parquet-go/format" 10 ) 11 12 const ( 13 MaxFixedLenByteArraySize = math.MaxInt16 14 ) 15 16 // The Encoding interface is implemented by types representing parquet column 17 // encodings. 18 // 19 // Encoding instances must be safe to use concurrently from multiple goroutines. 20 type Encoding interface { 21 // Returns a human-readable name for the encoding. 22 String() string 23 24 // Returns the parquet code representing the encoding. 25 Encoding() format.Encoding 26 27 // Encode methods serialize the source sequence of values into the 28 // destination buffer, potentially reallocating it if it was too short to 29 // contain the output. 30 // 31 // The methods panic if the type of src values differ from the type of 32 // values being encoded. 33 EncodeLevels(dst []byte, src []uint8) ([]byte, error) 34 EncodeBoolean(dst []byte, src []byte) ([]byte, error) 35 EncodeInt32(dst []byte, src []int32) ([]byte, error) 36 EncodeInt64(dst []byte, src []int64) ([]byte, error) 37 EncodeInt96(dst []byte, src []deprecated.Int96) ([]byte, error) 38 EncodeFloat(dst []byte, src []float32) ([]byte, error) 39 EncodeDouble(dst []byte, src []float64) ([]byte, error) 40 EncodeByteArray(dst []byte, src []byte, offsets []uint32) ([]byte, error) 41 EncodeFixedLenByteArray(dst []byte, src []byte, size int) ([]byte, error) 42 43 // Decode methods deserialize from the source buffer into the destination 44 // slice, potentially growing it if it was too short to contain the result. 45 // 46 // The methods panic if the type of dst values differ from the type of 47 // values being decoded. 48 DecodeLevels(dst []uint8, src []byte) ([]uint8, error) 49 DecodeBoolean(dst []byte, src []byte) ([]byte, error) 50 DecodeInt32(dst []int32, src []byte) ([]int32, error) 51 DecodeInt64(dst []int64, src []byte) ([]int64, error) 52 DecodeInt96(dst []deprecated.Int96, src []byte) ([]deprecated.Int96, error) 53 DecodeFloat(dst []float32, src []byte) ([]float32, error) 54 DecodeDouble(dst []float64, src []byte) ([]float64, error) 55 DecodeByteArray(dst []byte, src []byte, offsets []uint32) ([]byte, []uint32, error) 56 DecodeFixedLenByteArray(dst []byte, src []byte, size int) ([]byte, error) 57 58 // Computes an estimation of the output size of decoding the encoded page 59 // of values passed as argument. 60 // 61 // Note that this is an estimate, it is useful to preallocate the output 62 // buffer that will be passed to the decode method, but the actual output 63 // size may be different. 64 // 65 // The estimate never errors since it is not intended to be used as an 66 // input validation method. 67 EstimateDecodeByteArraySize(src []byte) int 68 69 // When this method returns true, the encoding supports receiving the same 70 // buffer as source and destination. 71 CanDecodeInPlace() bool 72 }