diff options
author | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
---|---|---|
committer | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
commit | bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch) | |
tree | ca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/hashicorp/terraform/config/module/tree_gob.go | |
parent | 254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff) | |
download | terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip |
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/config/module/tree_gob.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/config/module/tree_gob.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/config/module/tree_gob.go b/vendor/github.com/hashicorp/terraform/config/module/tree_gob.go new file mode 100644 index 0000000..fcd37f4 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/config/module/tree_gob.go | |||
@@ -0,0 +1,57 @@ | |||
1 | package module | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "encoding/gob" | ||
6 | |||
7 | "github.com/hashicorp/terraform/config" | ||
8 | ) | ||
9 | |||
10 | func (t *Tree) GobDecode(bs []byte) error { | ||
11 | t.lock.Lock() | ||
12 | defer t.lock.Unlock() | ||
13 | |||
14 | // Decode the gob data | ||
15 | var data treeGob | ||
16 | dec := gob.NewDecoder(bytes.NewReader(bs)) | ||
17 | if err := dec.Decode(&data); err != nil { | ||
18 | return err | ||
19 | } | ||
20 | |||
21 | // Set the fields | ||
22 | t.name = data.Name | ||
23 | t.config = data.Config | ||
24 | t.children = data.Children | ||
25 | t.path = data.Path | ||
26 | |||
27 | return nil | ||
28 | } | ||
29 | |||
30 | func (t *Tree) GobEncode() ([]byte, error) { | ||
31 | data := &treeGob{ | ||
32 | Config: t.config, | ||
33 | Children: t.children, | ||
34 | Name: t.name, | ||
35 | Path: t.path, | ||
36 | } | ||
37 | |||
38 | var buf bytes.Buffer | ||
39 | enc := gob.NewEncoder(&buf) | ||
40 | if err := enc.Encode(data); err != nil { | ||
41 | return nil, err | ||
42 | } | ||
43 | |||
44 | return buf.Bytes(), nil | ||
45 | } | ||
46 | |||
47 | // treeGob is used as a structure to Gob encode a tree. | ||
48 | // | ||
49 | // This structure is private so it can't be referenced but the fields are | ||
50 | // public, allowing Gob to properly encode this. When we decode this, we are | ||
51 | // able to turn it into a Tree. | ||
52 | type treeGob struct { | ||
53 | Config *config.Config | ||
54 | Children map[string]*Tree | ||
55 | Name string | ||
56 | Path []string | ||
57 | } | ||