-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
51 lines (43 loc) · 890 Bytes
/
examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package codec_test
import (
"bytes"
"fmt"
"log"
"os"
"github.com/jba/codec"
)
func Example() {
var buf bytes.Buffer
e := codec.NewEncoder(&buf, nil)
for _, x := range []interface{}{1, "hello", true} {
if err := e.Encode(x); err != nil {
log.Fatal(err)
}
}
d := codec.NewDecoder(bytes.NewReader(buf.Bytes()), nil)
for i := 0; i < 3; i++ {
var got interface{}
err := d.Decode(&got)
if err != nil {
log.Fatal(err)
}
fmt.Println(got)
}
// Output:
// 1
// hello
// true
}
func ExampleGenerateFile() {
err := codec.GenerateFile("types.gen.go", "mypkg", nil, []int{}, map[string]bool{})
if err != nil {
log.Fatal(err)
}
fmt.Println(err)
os.Remove("types.gen.go")
// Output:
// <nil>
}