github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/encoding/bytestreamsplit/bytestreamsplit.go (about) 1 package bytestreamsplit 2 3 import ( 4 "github.com/vc42/parquet-go/encoding" 5 "github.com/vc42/parquet-go/format" 6 ) 7 8 // This encoder implements a version of the Byte Stream Split encoding as described 9 // in https://github.com/apache/parquet-format/blob/master/Encodings.md#byte-stream-split-byte_stream_split--9 10 type Encoding struct { 11 encoding.NotSupported 12 } 13 14 func (e *Encoding) String() string { 15 return "BYTE_STREAM_SPLIT" 16 } 17 18 func (e *Encoding) Encoding() format.Encoding { 19 return format.ByteStreamSplit 20 } 21 22 func (e *Encoding) EncodeFloat(dst, src []byte) ([]byte, error) { 23 if (len(src) % 4) != 0 { 24 return dst[:0], encoding.ErrEncodeInvalidInputSize(e, "FLOAT", len(src)) 25 } 26 dst = resize(dst, len(src)) 27 encodeFloat(dst, src) 28 return dst, nil 29 } 30 31 func (e *Encoding) EncodeDouble(dst, src []byte) ([]byte, error) { 32 if (len(src) % 8) != 0 { 33 return dst[:0], encoding.ErrEncodeInvalidInputSize(e, "DOUBLE", len(src)) 34 } 35 dst = resize(dst, len(src)) 36 encodeDouble(dst, src) 37 return dst, nil 38 } 39 40 func (e *Encoding) DecodeFloat(dst, src []byte) ([]byte, error) { 41 if (len(src) % 4) != 0 { 42 return dst[:0], encoding.ErrDecodeInvalidInputSize(e, "FLOAT", len(src)) 43 } 44 dst = resize(dst, len(src)) 45 decodeFloat(dst, src) 46 return dst, nil 47 } 48 49 func (e *Encoding) DecodeDouble(dst, src []byte) ([]byte, error) { 50 if (len(src) % 8) != 0 { 51 return dst[:0], encoding.ErrDecodeInvalidInputSize(e, "DOUBLE", len(src)) 52 } 53 dst = resize(dst, len(src)) 54 decodeDouble(dst, src) 55 return dst, nil 56 } 57 58 func resize(buf []byte, size int) []byte { 59 if cap(buf) < size { 60 buf = make([]byte, size) 61 } else { 62 buf = buf[:size] 63 } 64 return buf 65 }