10 // GobEncode is an implementation of the gob.GobEncoder interface, which
11 // allows Values to be included in structures encoded with encoding/gob.
13 // Currently it is not possible to represent values of capsule types in gob,
14 // because the types themselves cannot be represented.
15 func (val Value) GobEncode() ([]byte, error) {
16 buf := &bytes.Buffer{}
17 enc := gob.NewEncoder(buf)
27 return nil, fmt.Errorf("error encoding cty.Value: %s", err)
30 return buf.Bytes(), nil
33 // GobDecode is an implementation of the gob.GobDecoder interface, which
34 // inverts the operation performed by GobEncode. See the documentation of
35 // GobEncode for considerations when using cty.Value instances with gob.
36 func (val *Value) GobDecode(buf []byte) error {
37 r := bytes.NewReader(buf)
38 dec := gob.NewDecoder(r)
41 err := dec.Decode(&gv)
43 return fmt.Errorf("error decoding cty.Value: %s", err)
46 return fmt.Errorf("unsupported cty.Value encoding version %d; only 0 is supported", gv.Version)
49 // big.Float seems to, for some reason, lose its "pointerness" when we
50 // round-trip it, so we'll fix that here.
51 if bf, ok := gv.V.(big.Float); ok {
61 // GobEncode is an implementation of the gob.GobEncoder interface, which
62 // allows Types to be included in structures encoded with encoding/gob.
64 // Currently it is not possible to represent capsule types in gob.
65 func (t Type) GobEncode() ([]byte, error) {
66 buf := &bytes.Buffer{}
67 enc := gob.NewEncoder(buf)
76 return nil, fmt.Errorf("error encoding cty.Type: %s", err)
79 return buf.Bytes(), nil
82 // GobDecode is an implementatino of the gob.GobDecoder interface, which
83 // reverses the encoding performed by GobEncode to allow types to be recovered
85 func (t *Type) GobDecode(buf []byte) error {
86 r := bytes.NewReader(buf)
87 dec := gob.NewDecoder(r)
90 err := dec.Decode(>)
92 return fmt.Errorf("error decoding cty.Type: %s", err)
95 return fmt.Errorf("unsupported cty.Type encoding version %d; only 0 is supported", gt.Version)
103 // Capsule types cannot currently be gob-encoded, because they rely on pointer
104 // equality and we have no way to recover the original pointer on decode.
105 func (t *capsuleType) GobEncode() ([]byte, error) {
106 return nil, fmt.Errorf("cannot gob-encode capsule type %q", t.FriendlyName(friendlyTypeName))
109 func (t *capsuleType) GobDecode() ([]byte, error) {
110 return nil, fmt.Errorf("cannot gob-decode capsule type %q", t.FriendlyName(friendlyTypeName))
113 type gobValue struct {
119 type gobType struct {
124 type gobCapsuleTypeImpl struct {