-
Notifications
You must be signed in to change notification settings - Fork 0
/
wireconfig.go
59 lines (51 loc) · 1.52 KB
/
wireconfig.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
package polo
// wireConfig defines the wire encoding/decoding
// configuration for Polorizer or Depolorizer
type wireConfig struct {
packBytes bool
docStructs bool
docStrMaps bool
}
// defaultConfig returns a default wireConfig object
func defaultWireConfig() *wireConfig {
return &wireConfig{
packBytes: false,
docStructs: false,
docStrMaps: false,
}
}
func (cfg *wireConfig) apply(options ...EncodingOptions) {
for _, opt := range options {
opt(cfg)
}
}
// EncodingOptions represents options that can be provided to
// encoding/decoding functions or buffers to modify the wire form
type EncodingOptions func(*wireConfig)
// PackedBytes is an EncodingOption that sets the encoding/decoding
// to interpret bytes as pack-encoded uint8 values instead of a word
func PackedBytes() EncodingOptions {
return func(config *wireConfig) {
config.packBytes = true
}
}
// DocStructs is an EncodingOption that sets the encoding/decoding
// to interpret structs as document-encoded values instead of a pack
func DocStructs() EncodingOptions {
return func(config *wireConfig) {
config.docStructs = true
}
}
// DocStringMaps is an EncodingOption that sets the encoding/decoding to
// interpret string keyed maps as document-encoded values instead of a pack
func DocStringMaps() EncodingOptions {
return func(config *wireConfig) {
config.docStrMaps = true
}
}
// inheritCfg is an EncodingOption that inherits the full config
func inheritCfg(inherit wireConfig) EncodingOptions {
return func(config *wireConfig) {
*config = inherit
}
}