Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d47b07b

Browse files
authoredDec 11, 2016
Update api.md
1 parent b5423c1 commit d47b07b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed
 

‎api.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,31 @@ iter.Read(&abc)
3333
fmt.Println(abc.a.Get("b", "c"))
3434
```
3535

36-
Tranditionally, parse json return `Object` or `interface{}`. Then the parer's job is done, and developer's nightmare begins. Being able to mix bind-api and any-api, we can leave certain value uncertain, and deal with them later. `Any` has api to extract data out of deeply nested data structure very easily.
36+
Tranditionally, parse json return `Object` or `interface{}`. Then the parer's job is done, and developer's nightmare begins. Being able to mix bind-api and any-api, we can leave parts of the value uncertain, and deal with them later. `Any` has api to extract data out of deeply nested data structure very easily.
3737

38+
Here is another example, `[123, {"name": "taowen", "tags": ["crazy", "hacker"]}]`
39+
40+
Parse with Go iterator-api + bind-api
41+
42+
```
43+
iter := ParseString(`[123, {"name": "taowen", "tags": ["crazy", "hacker"]}]`)
44+
user := User{}
45+
iter.ReadArray()
46+
user.userId = iter.ReadInt()
47+
iter.ReadArray()
48+
iter.Read(&user)
49+
iter.ReadArray() // array end
50+
fmt.Println(user)
51+
```
52+
53+
Use iterator api gives us flexibility to do whatever we want. But binding a big struct is not fun to do manually. By mixing bind-api with iterator-api we can save some effort without compromising performance. Binding is fast. Handwritten binding code is only 10% faster or less.
54+
55+
Here is a list of possible hybrid combination:
56+
57+
* iterator-api => bind-api: use `Read`
58+
* iterator-api => any-api: use `ReadAny`
59+
* bind-api => iterator-api: register type decoder or field decoder
60+
* bind-api => any-api: use `Any` as data type
3861

3962
# Iterator API
4063

0 commit comments

Comments
 (0)
Please sign in to comment.