// Format transforms collectd data to influx 0.9.x data
func (format *CollectdToInflux10) Format(msg core.Message) ([]byte, core.MessageStreamID) {
	data, streamID := format.base.Format(msg)
	collectdData, err := parseCollectdPacket(data)
	if err != nil {
		Log.Error.Print("Collectd parser error: ", err)
		return []byte{}, streamID // ### return, error ###
	}

	// Manually convert to line protocol
	influxData := shared.NewByteStream(len(data))
	timestamp := int64(collectdData.Time * 1000)
	fixedPart := fmt.Sprintf(
		`%s,plugin_instance=%s,type=%s,type_instance=%s,host=%s`,
		format.escapeTag(collectdData.Plugin),
		format.escapeTag(collectdData.PluginInstance),
		format.escapeTag(collectdData.PluginType),
		format.escapeTag(collectdData.TypeInstance),
		format.escapeTag(collectdData.Host))

	setSize := shared.Min3I(len(collectdData.Dstypes), len(collectdData.Dsnames), len(collectdData.Values))
	for i := 0; i < setSize; i++ {
		fmt.Fprintf(&influxData,
			`%s,dstype=%s,dsname=%s value=%f %d\n`,
			fixedPart,
			format.escapeTag(collectdData.Dstypes[i]),
			format.escapeTag(collectdData.Dsnames[i]),
			collectdData.Values[i],
			timestamp)
	}

	return influxData.Bytes(), streamID
}
// Format transforms collectd data to influx 0.9.x data
func (format *CollectdToInflux09) Format(msg core.Message) ([]byte, core.MessageStreamID) {
	data, streamID := format.base.Format(msg)
	collectdData, err := parseCollectdPacket(data)
	if err != nil {
		Log.Error.Print("Collectd parser error: ", err)
		return []byte{}, streamID // ### return, error ###
	}

	// Manually convert to JSON lines
	influxData := shared.NewByteStream(len(data))
	fixedPart := fmt.Sprintf(
		`{"name": "%s", "timestamp": %d, "precision": "ms", "tags": {"plugin_instance": "%s", "type": "%s", "type_instance": "%s", "host": "%s"`,
		collectdData.Plugin,
		int64(collectdData.Time),
		collectdData.PluginInstance,
		collectdData.PluginType,
		collectdData.TypeInstance,
		collectdData.Host)

	setSize := shared.Min3I(len(collectdData.Dstypes), len(collectdData.Dsnames), len(collectdData.Values))
	for i := 0; i < setSize; i++ {
		fmt.Fprintf(&influxData,
			`%s, "dstype": "%s", "dsname": "%s"}, "fields": {"value": %f} },`,
			fixedPart,
			collectdData.Dstypes[i],
			collectdData.Dsnames[i],
			collectdData.Values[i])
	}

	return influxData.Bytes(), streamID
}