...
1 package example
2
3 import (
4 "bytes"
5 "fmt"
6 "strings"
7 "github.com/bytedance/sonic"
8 )
9
10
11 func ExampleStreamDecoder() {
12 var o = map[string]interface{}{}
13 var r = strings.NewReader(`{"a":"b"}{"1":"2"}`)
14 var dec = sonic.ConfigDefault.NewDecoder(r)
15 dec.Decode(&o)
16 dec.Decode(&o)
17 fmt.Printf("%+v", o)
18
19
20 }
21
22
23
24 func ExampleStreamEncoder() {
25 var o1 = map[string]interface{}{
26 "a": "b",
27 }
28 var o2 = 1
29 var w = bytes.NewBuffer(nil)
30 var enc = sonic.ConfigDefault.NewEncoder(w)
31 enc.Encode(o1)
32 enc.Encode(o2)
33 fmt.Println(w.String())
34
35
36
37 }
View as plain text