You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"os""github.com/francoispqt/gojay"
)
// Our structure which will be pushed to our streamtypeuserstruct {
idintnamestringemailstring
}
func (u*user) MarshalJSONObject(enc*gojay.Encoder) {
enc.IntKey("id", u.id)
enc.StringKey("name", u.name)
enc.StringKey("email", u.email)
}
func (u*user) IsNil() bool {
returnu==nil
}
// Our MarshalerStream implementationtypeStreamChanchan*userfunc (sStreamChan) MarshalStream(enc*gojay.StreamEncoder) {
select {
case<-enc.Done():
returncaseo:=<-s:
enc.Object(o)
}
}
// Our main functionfuncmain() {
// we borrow an encoder set stdout as the writer,// set the number of consumer to 10// and tell the encoder to separate each encoded element// added to the channel by a new line characterenc:=gojay.Stream.BorrowEncoder(os.Stdout).NConsumer(10).LineDelimited()
// instantiate our MarshalerStreams:=StreamChan(make(chan*user))
// start the stream encoder// will block its goroutine until enc.Cancel(error) is called// or until something is written to the channelgoenc.EncodeStream(s)
// write to our MarshalerStreamfori:=0; i<1000; i++ {
s<-&user{i, "username", "user@email.com"}
}
// Wait<-enc.Done()
}
The text was updated successfully, but these errors were encountered:
Modifying the streaming encoder to write to stdout causes a panic:
with this program:
The text was updated successfully, but these errors were encountered: