-
Notifications
You must be signed in to change notification settings - Fork 1
/
msgpack.go
39 lines (33 loc) · 1002 Bytes
/
msgpack.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
package msgpack
import (
"github.com/shamaton/msgpack/v2"
)
// Marshal returns the MessagePack-encoded byte array of v.
func Marshal(v interface{}) ([]byte, error) {
if StructAsArray() {
return MarshalAsArray(v)
}
return MarshalAsMap(v)
}
// Unmarshal analyzes the MessagePack-encoded data and stores
// the result into the pointer of v.
func Unmarshal(data []byte, v interface{}) error {
if StructAsArray() {
return UnmarshalAsArray(data, v)
}
return UnmarshalAsMap(data, v)
}
// SetStructAsArray sets default encoding option.
// If this option sets true, default encoding sets to array-format.
func SetStructAsArray(on bool) {
msgpack.StructAsArray = on
}
// StructAsArray gets default encoding option.
// If this option sets true, default encoding sets to array-format.
func StructAsArray() bool {
return msgpack.StructAsArray
}
// SetComplexTypeCode sets def.complexTypeCode in github.com/shamaton/msgpack
func SetComplexTypeCode(code int8) {
msgpack.SetComplexTypeCode(code)
}