forked from segmentio/parquet-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bytestreamsplit.go
65 lines (56 loc) · 1.58 KB
/
bytestreamsplit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package bytestreamsplit
import (
"github.com/vc42/parquet-go/encoding"
"github.com/vc42/parquet-go/format"
)
// 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 (e *Encoding) String() string {
return "BYTE_STREAM_SPLIT"
}
func (e *Encoding) Encoding() format.Encoding {
return format.ByteStreamSplit
}
func (e *Encoding) EncodeFloat(dst, src []byte) ([]byte, error) {
if (len(src) % 4) != 0 {
return dst[:0], encoding.ErrEncodeInvalidInputSize(e, "FLOAT", len(src))
}
dst = resize(dst, len(src))
encodeFloat(dst, src)
return dst, nil
}
func (e *Encoding) EncodeDouble(dst, src []byte) ([]byte, error) {
if (len(src) % 8) != 0 {
return dst[:0], encoding.ErrEncodeInvalidInputSize(e, "DOUBLE", len(src))
}
dst = resize(dst, len(src))
encodeDouble(dst, src)
return dst, nil
}
func (e *Encoding) DecodeFloat(dst, src []byte) ([]byte, error) {
if (len(src) % 4) != 0 {
return dst[:0], encoding.ErrDecodeInvalidInputSize(e, "FLOAT", len(src))
}
dst = resize(dst, len(src))
decodeFloat(dst, src)
return dst, nil
}
func (e *Encoding) DecodeDouble(dst, src []byte) ([]byte, error) {
if (len(src) % 8) != 0 {
return dst[:0], encoding.ErrDecodeInvalidInputSize(e, "DOUBLE", len(src))
}
dst = resize(dst, len(src))
decodeDouble(dst, src)
return dst, nil
}
func resize(buf []byte, size int) []byte {
if cap(buf) < size {
buf = make([]byte, size)
} else {
buf = buf[:size]
}
return buf
}