Exemple #1
0
// Decode the data from the supplied reader.
// You should expect that data is read into memory before it is decoded.
func (d *Decoder) DecodeReader(r io.Reader, v interface{}) error {
	_, ok := v.(unmarshalFaster)
	_, ok2 := v.(json.Unmarshaler)
	if ok || ok2 {
		data, err := ioutil.ReadAll(r)
		if err != nil {
			return err
		}
		defer fflib.Pool(data)
		return d.Decode(data, v)
	}
	dec := json.NewDecoder(r)
	return dec.Decode(v)
}
Exemple #2
0
// Send a buffer to the Pool to reuse for other instances.
//
// On servers where you have a lot of concurrent encoding going on,
// you can hand back the byte buffer you get marshalling once you are done using it.
//
// You may no longer utilize the content of the buffer, since it may be used
// by other goroutines.
func Pool(b []byte) {
	fflib.Pool(b)
}