-
Notifications
You must be signed in to change notification settings - Fork 0
/
decompress.go
52 lines (38 loc) · 964 Bytes
/
decompress.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
package zstd_marshal
import (
"encoding/json"
"github.com/klauspost/compress/zstd"
)
type zstdDecoder struct {
*zstd.Decoder
}
// UnmarshalWithConcurrency - convert zstd encoded data to struct with concurrency
func UnmarshalWithConcurrency(data []byte, v interface{}, concurrency int) error {
// init zstd decoder with set concurrency
decoder := newZstdDecoderWithConcurrency(concurrency)
defer decoder.Close()
decodedData, err := decoder.DecodeAll(data, nil)
if err != nil {
return err
}
err = json.Unmarshal(decodedData, v)
if err != nil {
return err
}
return nil
}
// Unmarshal - convert zstd encoded data to struct
func Unmarshal(data []byte, v interface{}) error {
// init zstd decoder with set concurrency
decoder := newZstdDecoder()
defer decoder.Close()
decodedData, err := decoder.DecodeAll(data, nil)
if err != nil {
return err
}
err = json.Unmarshal(decodedData, v)
if err != nil {
return err
}
return nil
}