MCPcopy Index your code
hub / github.com/frain-dev/convoy / EncodeMsgPack

Function EncodeMsgPack

pkg/msgpack/msgpack.go:20–38  ·  view source on GitHub ↗
(payload interface{})

Source from the content-addressed store, hash-verified

18}
19
20func EncodeMsgPack(payload interface{}) ([]byte, error) {
21 // Get buffer from pool
22 buf := bufferPool.Get().(*bytes.Buffer)
23 buf.Reset() // Clear previous contents
24 defer bufferPool.Put(buf)
25
26 enc := msgpack.NewEncoder(buf)
27 enc.SetCustomStructTag("json")
28
29 err := enc.Encode(payload)
30 if err != nil {
31 return nil, err
32 }
33
34 // Must make a copy since we're returning buffer to pool
35 result := make([]byte, buf.Len())
36 copy(result, buf.Bytes())
37 return result, nil
38}
39
40func DecodeMsgPack(pack []byte, target interface{}) error {
41 var buf bytes.Buffer

Calls 3

LenMethod · 0.80
GetMethod · 0.65
ResetMethod · 0.45