mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 01:26:43 +00:00
![Riley Karson](/assets/img/avatar_default.png)
```bash GO111MODULE=on go get github.com/hashicorp/terraform@pluginsdk-v0.12-early7 GO111MODULE=on go mod vendor GO111MODULE=on go mod tidy ```
32 lines
707 B
Go
32 lines
707 B
Go
package msgpack
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/vmihailenco/msgpack"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
type dynamicVal struct {
|
|
Value cty.Value
|
|
Path cty.Path
|
|
}
|
|
|
|
func (dv *dynamicVal) MarshalMsgpack() ([]byte, error) {
|
|
// Rather than defining a msgpack-specific serialization of types,
|
|
// instead we use the existing JSON serialization.
|
|
typeJSON, err := dv.Value.Type().MarshalJSON()
|
|
if err != nil {
|
|
return nil, dv.Path.NewErrorf("failed to serialize type: %s", err)
|
|
}
|
|
var buf bytes.Buffer
|
|
enc := msgpack.NewEncoder(&buf)
|
|
enc.EncodeArrayLen(2)
|
|
enc.EncodeBytes(typeJSON)
|
|
err = marshal(dv.Value, dv.Value.Type(), dv.Path, enc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return buf.Bytes(), nil
|
|
}
|