Currently the way to convert an object to json and gzip it is:
jsonBytes, _ := json.Marshal(payload)
//gzip json
var body bytes.Buffer
g := gzip.NewWriter(&body)
g.Write(jsonBytes)
g.Close()
This results in an intermediate large byte buffer jsonBytes
, whose only purpose is to be then converted into gzipped buffer.
Is there any way to stream the marshalling of the payload
object so it comes out gzipped in the first place?
Streaming Encoders and Decoders
– Caenogenesis