blob: 9492f67d51c32aa50018142970901a40495bcf52 (
plain) (
blame)
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 object // import "github.com/SevereCloud/vksdk/v2/object"
import "github.com/vmihailenco/msgpack/v5"
// RawMessage is a raw encoded JSON or MessagePack value.
type RawMessage []byte
// MarshalJSON returns m as the JSON encoding of m.
func (m RawMessage) MarshalJSON() ([]byte, error) {
if m == nil {
return []byte("null"), nil
}
return m, nil
}
// UnmarshalJSON sets *m to a copy of data.
func (m *RawMessage) UnmarshalJSON(data []byte) error {
*m = append((*m)[0:0], data...)
return nil
}
// EncodeMsgpack write m as the MessagePack encoding of m.
func (m RawMessage) EncodeMsgpack(enc *msgpack.Encoder) error {
_, err := enc.Writer().Write(m)
return err
}
// DecodeMsgpack sets *m to a copy of data.
func (m *RawMessage) DecodeMsgpack(dec *msgpack.Decoder) error {
msg, err := dec.DecodeRaw()
if err != nil {
return err
}
*m = RawMessage(msg)
return nil
}
|