func ToCorePluginsMsg(pls []core.Plugin) []*Plugin {
	plugins := make([]*Plugin, len(pls))
	for i, v := range pls {
		plugins[i] = ToCorePluginMsg(v)
	}
	return plugins
}
Convert from Plugin protobuf message to core.Plugin
package common
import (
	"errors"
	"fmt"
	"strconv"
	"time"
	"github.com/intelsdi-x/snap/core"
	"github.com/intelsdi-x/snap/core/cdata"
	"github.com/intelsdi-x/snap/core/ctypes"
	"github.com/intelsdi-x/snap/core/serror"
	log "github.com/sirupsen/logrus"
)
func ToMetric(co core.Metric) *Metric {
	cm := &Metric{
		Namespace: ToNamespace(co.Namespace()),
		Version:   int64(co.Version()),
		Tags:      co.Tags(),
		Timestamp: &Time{
			Sec:  co.Timestamp().Unix(),
			Nsec: int64(co.Timestamp().Nanosecond()),
		},
		LastAdvertisedTime: &Time{
			Sec:  time.Now().Unix(),
			Nsec: int64(time.Now().Nanosecond()),
		},
	}
	if co.Config() != nil {
		cm.Config = ConfigToConfigMap(co.Config())
	}
	switch t := co.Data().(type) {
	case string:
		cm.Data = &Metric_StringData{t}
	case float64:
		cm.Data = &Metric_Float64Data{t}
	case float32:
		cm.Data = &Metric_Float32Data{t}
	case int32:
		cm.Data = &Metric_Int32Data{t}
	case int:
		cm.Data = &Metric_Int64Data{int64(t)}
	case int64:
		cm.Data = &Metric_Int64Data{t}
	case uint32:
		cm.Data = &Metric_Uint32Data{t}
	case uint64:
		cm.Data = &Metric_Uint64Data{t}
	case []byte:
		cm.Data = &Metric_BytesData{t}
	case bool:
		cm.Data = &Metric_BoolData{t}
	case nil:
		cm.Data = nil
	default:
		panic(fmt.Sprintf("unsupported type: %s", t))
	}
	return cm
}
func ToNamespace(n core.Namespace) []*NamespaceElement {
	elements := make([]*NamespaceElement, 0, len(n))
	for _, value := range n {
		ne := &NamespaceElement{
			Value:       value.Value,
			Description: value.Description,
			Name:        value.Name,
		}
		elements = append(elements, ne)
	}
	return elements
}
func ToTime(t time.Time) *Time {
	return &Time{
		Nsec: t.Unix(),
		Sec:  int64(t.Second()),
	}
}
func NewMetrics(ms []core.Metric) []*Metric {
	metrics := make([]*Metric, len(ms))
	for i, m := range ms {
		metrics[i] = ToMetric(m)
	}
	return metrics
}
type metric struct {
	namespace          core.Namespace
	version            int
	config             *cdata.ConfigDataNode
	lastAdvertisedTime time.Time
	timeStamp          time.Time
	data               interface{}
	tags               map[string]string
	description        string
	unit               string
}
func (m *metric) Namespace() core.Namespace     { return m.namespace }
func (m *metric) Config() *cdata.ConfigDataNode { return m.config }
func (m *metric) Version() int                  { return m.version }
func (m *metric) Data() interface{}             { return m.data }
func (m *metric) Tags() map[string]string       { return m.tags }
func (m *metric) LastAdvertisedTime() time.Time { return m.lastAdvertisedTime }
func (m *metric) Timestamp() time.Time          { return m.timeStamp }
func (m *metric) Description() string           { return m.description }
func (m *metric) Unit() string                  { return m.unit }
func ToCoreMetric(mt *Metric) core.Metric {
	var lastAdvertisedTime time.Time
	if mt.LastAdvertisedTime.Sec == int64(-62135596800) {
		lastAdvertisedTime = time.Unix(time.Now().Unix(), int64(time.Now().Nanosecond()))
	} else {
		lastAdvertisedTime = time.Unix(mt.LastAdvertisedTime.Sec, mt.LastAdvertisedTime.Nsec)
	}
	ret := &metric{
		namespace:          ToCoreNamespace(mt.Namespace),
		version:            int(mt.Version),
		tags:               mt.Tags,
		timeStamp:          time.Unix(mt.Timestamp.Sec, mt.Timestamp.Nsec),
		lastAdvertisedTime: lastAdvertisedTime,
		config:             ConfigMapToConfig(mt.Config),
		description:        mt.Description,
		unit:               mt.Unit,
	}
	switch mt.Data.(type) {
	case *Metric_BytesData:
		ret.data = mt.GetBytesData()
	case *Metric_StringData:
		ret.data = mt.GetStringData()
	case *Metric_Float32Data:
		ret.data = mt.GetFloat32Data()
	case *Metric_Float64Data:
		ret.data = mt.GetFloat64Data()
	case *Metric_Int32Data:
		ret.data = mt.GetInt32Data()
	case *Metric_Int64Data:
		ret.data = mt.GetInt64Data()
	case *Metric_Uint32Data:
		ret.data = mt.GetUint32Data()
	case *Metric_Uint64Data:
		ret.data = mt.GetUint64Data()
	case *Metric_BoolData:
		ret.data = mt.GetBoolData()
	}
	return ret
}
func MetricToRequested(mts []*Metric) []core.RequestedMetric {
	ret := make([]core.RequestedMetric, len(mts))
	for i, mt := range mts {
		met := &metric{
			namespace: ToCoreNamespace(mt.Namespace),
			version:   int(mt.Version),
		}
		ret[i] = met
	}
	return ret
}
func ToCoreNamespace(n []*NamespaceElement) core.Namespace {
	var namespace core.Namespace
	for _, val := range n {
		ele := core.NamespaceElement{
			Value:       val.Value,
			Description: val.Description,
			Name:        val.Name,
		}
		namespace = append(namespace, ele)
	}
	return namespace
}
func ToCoreMetrics(mts []*Metric) []core.Metric {
	metrics := make([]core.Metric, len(mts))
	for i, mt := range mts {
		metrics[i] = ToCoreMetric(mt)
	}
	return metrics
}
func ToRequestedMetrics(mts []*Metric) []core.RequestedMetric {
	metrics := make([]core.RequestedMetric, len(mts))
	for i, mt := range mts {
		metrics[i] = ToCoreMetric(mt)
	}
	return metrics
}
func RequestedToMetric(requested []core.RequestedMetric) []*Metric {
	reqMets := make([]*Metric, len(requested))
	for i, r := range requested {
		rm := &Metric{
			Namespace: ToNamespace(r.Namespace()),
			Version:   int64(r.Version()),
			Config:    &ConfigMap{},
			Tags:      map[string]string{},
			Timestamp: &Time{
				Sec:  time.Now().Unix(),
				Nsec: int64(time.Now().Nanosecond()),
			},
			LastAdvertisedTime: &Time{
				Sec:  time.Now().Unix(),
				Nsec: int64(time.Now().Nanosecond()),
			},
		}
		reqMets[i] = rm
	}
	return reqMets
}
type SubPlugin struct {
	typeName string
	name     string
	version  int
	config   *cdata.ConfigDataNode
}
func (sp SubPlugin) TypeName() string {
	return sp.typeName
}
func (sp SubPlugin) Name() string {
	return sp.name
}
func (sp SubPlugin) Version() int {
	return sp.version
}
func (sp SubPlugin) Config() *cdata.ConfigDataNode {
	return sp.config
}
func ToCorePlugin(pl core.SubscribedPlugin) core.Plugin {
	return core.Plugin(pl)
}
func ToCorePlugins(pl []core.SubscribedPlugin) []core.Plugin {
	plugins := make([]core.Plugin, len(pl))
	for i, v := range pl {
		plugins[i] = v
	}
	return plugins
}
func ToSubPluginMsg(pl core.SubscribedPlugin) *SubscribedPlugin {
	return &SubscribedPlugin{
		TypeName: pl.TypeName(),
		Name:     pl.Name(),
		Version:  int64(pl.Version()),
		Config:   ConfigToConfigMap(pl.Config()),
	}
}
func ToSubPlugin(msg *SubscribedPlugin) core.SubscribedPlugin {
	return SubPlugin{
		typeName: msg.TypeName,
		name:     msg.Name,
		version:  int(msg.Version),
		config:   ConfigMapToConfig(msg.Config),
	}
}
func ToCorePluginMsg(pl core.Plugin) *Plugin {
	return &Plugin{
		TypeName: pl.TypeName(),
		Name:     pl.Name(),
		Version:  int64(pl.Version()),
	}
}