francoispqt / gojay

high performance JSON encoder/decoder with stream API for Golang
MIT License
2.11k stars 112 forks source link

what's the proper way to encode []byte ? #47

Closed dcu closed 6 years ago

francoispqt commented 6 years ago

You can encode bytes this way:

type V struct {
    b []byte
}

func (v *V)  MarshalJSONObject(enc *gojay.Encoder) {
    var ej = gojay.EmbeddedJSON(v.b)
    enc.AddEmbeddedJSONKey("someKey", &ej)
    enc.AddEmbeddedJSONKeyOmitEmpty("someKeyOmitEmpty", &ej)
}

func (v *V)  IsNil() bool {
    return v == nil
}

Eventually will add a simple enc.Bytes in the future.

hjw6160602 commented 5 years ago

Then how can I decode []byte in the proper way when I used this AddEmbeddedJSONKey method?