gojay

high performance JSON encoder/decoder with stream API for Golang
git clone git://git.lair.cx/gojay
Log | Files | Refs | README | LICENSE

commit dd3bc129dd64a8ed3b9175610fc9f756bcd8b065
parent 0f58d9e9e06dda76b9dddfb16d1a4ab409e422b8
Author: francoispqt <francois@parquet.ninja>
Date:   Tue,  1 May 2018 23:49:19 +0800

update README

Diffstat:
MREADME.md | 24++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md @@ -299,12 +299,14 @@ func main() { with Encode: ```go func main() { - u := &user{1, "gojay", "gojay@email.com"} - b := strings.Builder{} - if err := gojay.NewEncoder(&b); err != nil { - log.Fatal(err) - } - fmt.Println(b.String()) // {"id":1,"name":"gojay","email":"gojay@email.com"} + func main() { + u := &user{1, "gojay", "gojay@email.com"} + b := strings.Builder{} + enc := gojay.NewEncoder(&b) + if err := enc.Encode(u); err != nil { + log.Fatal(err) + } + fmt.Println(b.String()) // {"id":1,"name":"gojay","email":"gojay@email.com"} } ``` @@ -526,7 +528,7 @@ func main() { } ``` -## Stream Encoding +### Stream Encoding GoJay ships with a powerful stream encoder part of the Stream API. It allows to write continuously to an io.Writer and do JIT encoding of data fed to a channel to allow async consuming. You can set multiple consumers on the channel to be as performant as possible. Consumers are non blocking and are scheduled individually in their own go routine. @@ -553,7 +555,7 @@ type user struct { func (u *user) MarshalObject(enc *gojay.Encoder) { enc.AddIntKey("id", u.id) enc.AddStringKey("name", u.name) - enc.AddStringKey("id", u.email) + enc.AddStringKey("email", u.email) } func (u *user) IsNil() bool { return u == nil @@ -589,16 +591,14 @@ func main() { s := StreamChan(make(chan *user)) // start the stream encoder // will block its goroutine until enc.Cancel(error) is called - // or until something is written to then channel + // or until something is written to the channel go enc.EncodeStream(s) // write to our MarshalerStream for i := 0; i < 1000; i++ { s<-&user{i,"username","user@email.com"} } // Wait - select { - case <-enc.Done(): - } + <-enc.Done() } ```