]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/zclconf/go-cty/cty/msgpack/dynamic.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / zclconf / go-cty / cty / msgpack / dynamic.go
1 package msgpack
2
3 import (
4 "bytes"
5
6 "github.com/vmihailenco/msgpack"
7 "github.com/zclconf/go-cty/cty"
8 )
9
10 type dynamicVal struct {
11 Value cty.Value
12 Path cty.Path
13 }
14
15 func (dv *dynamicVal) MarshalMsgpack() ([]byte, error) {
16 // Rather than defining a msgpack-specific serialization of types,
17 // instead we use the existing JSON serialization.
18 typeJSON, err := dv.Value.Type().MarshalJSON()
19 if err != nil {
20 return nil, dv.Path.NewErrorf("failed to serialize type: %s", err)
21 }
22 var buf bytes.Buffer
23 enc := msgpack.NewEncoder(&buf)
24 enc.EncodeArrayLen(2)
25 enc.EncodeBytes(typeJSON)
26 err = marshal(dv.Value, dv.Value.Type(), dv.Path, enc)
27 if err != nil {
28 return nil, err
29 }
30 return buf.Bytes(), nil
31 }