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
}
Convert common.Namespace protobuf message to core.Namespace
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
}