func (sl SketchSeriesList) MarshalJSON() ([]byte, error) {
	// We use this function to customize generated JSON
	// This function, only used when displaying `bins`, is especially slow
	// As `StructToMap` function is using reflection to return a generic map[string]interface{}
	customSketchSeries := func(srcSl SketchSeriesList) []interface{} {
		dstSl := make([]interface{}, 0, len(srcSl))

		for _, ss := range srcSl {
			ssMap := common.StructToMap(ss)
			for i, sketchPoint := range ss.Points {
				if sketchPoint.Sketch != nil {
					sketch := ssMap["points"].([]interface{})[i].(map[string]interface{})
					count, bins := sketchPoint.Sketch.GetRawBins()
					sketch["binsCount"] = count
					sketch["bins"] = bins
				}
			}

			dstSl = append(dstSl, ssMap)
		}

		return dstSl
	}

	// use an alias to avoid infinite recursion while serializing a SketchSeriesList
	if config.Datadog.GetBool("cmd.check.fullsketches") {
		data := map[string]interface{}{
			"sketches": customSketchSeries(sl),
		}

		reqBody := &bytes.Buffer{}
		err := json.NewEncoder(reqBody).Encode(data)
		return reqBody.Bytes(), err
	}

	type SketchSeriesAlias SketchSeriesList
	data := map[string]SketchSeriesAlias{
		"sketches": SketchSeriesAlias(sl),
	}

	reqBody := &bytes.Buffer{}
	err := json.NewEncoder(reqBody).Encode(data)
	return reqBody.Bytes(), err
}
// MarshalJSON serializes sketch series to JSON.
// Quite slow, but hopefully this method is called only in the `agent check` command
MarshalJSON serializes sketch series to JSON.
Quite slow, but hopefully this method is called only in the `agent check` command
// MarshalJSON serializes sketch series to JSON . // Quite slow but hopefully this method is called only in the ` agent check ` command
func (sl SketchSeriesList) MarshalJSON() ([]byte, error) {
	customSketchSeries := func(srcSl SketchSeriesList) []interface{} {
		dstSl := make([]interface{}, 0, len(srcSl))
		for _, ss := range srcSl {
			ssMap := common.StructToMap(ss)
			for i, sketchPoint := range ss.Points {
				if sketchPoint.Sketch != nil {
					sketch := ssMap["points"].([]interface{})[i].(map[string]interface{})
					count, bins := sketchPoint.Sketch.GetRawBins()
					sketch["binsCount"] = count
					sketch["bins"] = bins
				}
			}
			dstSl = append(dstSl, ssMap)
		}
		return dstSl
	}
	if config.Datadog.GetBool("cmd.check.fullsketches") {
		data := map[string]interface{}{
			"sketches": customSketchSeries(sl),
		}
		reqBody := &bytes.Buffer{}
		err := json.NewEncoder(reqBody).Encode(data)
		return reqBody.Bytes(), err
	}
	type SketchSeriesAlias SketchSeriesList
	data := map[string]SketchSeriesAlias{
		"sketches": SketchSeriesAlias(sl),
	}
	reqBody := &bytes.Buffer{}
	err := json.NewEncoder(reqBody).Encode(data)
	return reqBody.Bytes(), err
}
func ( sl SketchSeriesList ) MarshalJSON ( ) ( [ ] byte , error ) { customSketchSeries := func ( srcSl SketchSeriesList ) [ ] interface { } { dstSl := make ( [ ] interface { } , 0 , len ( srcSl ) ) for _ , ss := range srcSl { ssMap := common . StructToMap ( ss ) for i , sketchPoint := range ss . Points { if sketchPoint . Sketch != nil { sketch := ssMap [ " " ] . ( [ ] interface { } ) [ i ] . ( map [ string ] interface { } ) count , bins := sketchPoint . Sketch . GetRawBins ( ) sketch [ " " ] = count sketch [ " " ] = bins } } dstSl = append ( dstSl , ssMap ) } return dstSl } if config . Datadog . GetBool ( " " ) { data := map [ string ] interface { } { " " : customSketchSeries ( sl ) , } reqBody := & bytes . Buffer { } err := json . NewEncoder ( reqBody ) . Encode ( data ) return reqBody . Bytes ( ) , err } type SketchSeriesAlias SketchSeriesList data := map [ string ] SketchSeriesAlias { " " : SketchSeriesAlias ( sl ) , } reqBody := & bytes . Buffer { } err := json . NewEncoder ( reqBody ) . Encode ( data ) return reqBody . Bytes ( ) , err }
MarshalJSON serializes sketch series to JSON.
MarshalJSON serializes sketch series to JSON .
// We use this function to customize generated JSON // This function, only used when displaying `bins`, is especially slow // As `StructToMap` function is using reflection to return a generic map[string]interface{} // use an alias to avoid infinite recursion while serializing a SketchSeriesList