// ToProto implements the Metadata interface
495058
func (m GatewayIDMetadata) ToProto() *pb.Metadata {
	return &pb.Metadata{
		Metadata: &pb.Metadata_GatewayID{
			GatewayID: m.GatewayID,
		},
	}
}
905314
func (q *Quest) ToProto() *dm.Quest {
	return &dm.Quest{
		Id:   dm.NewQuestID(q.ID),
		Data: q.DataProto(),
	}
}
1107329
func (s *ConfigService) GetTopMenus() (*[]TopMenuEntryInfo, *Response, error) {
	u := "config/server/top-menus"

	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	v := new([]TopMenuEntryInfo)
	resp, err := s.client.Do(req, v)
	if err != nil {
		return nil, resp, err
	}

	return v, resp, err
}
49775
func (c *lruCache) Top() []bitmapPair {
	a := make([]bitmapPair, 0, len(c.counts))
	for id, n := range c.counts {
		a = append(a, bitmapPair{
			ID:    id,
			Count: n,
		})
	}
	sort.Sort(bitmapPairs(a))
	return a
}
1202047
func EventToProtocolBuffer(event *Event) (*proto.Event, error) {
	if event.Host == "" {
		event.Host, _ = os.Hostname()
	}

	if event.Time.IsZero() {
		event.Time = time.Now()
	}

	var e proto.Event

	e.Host = pb.String(event.Host)
	e.Time = pb.Int64(event.Time.Unix())
	e.TimeMicros = pb.Int64(event.Time.UnixNano() / int64(time.Microsecond))

	if event.Service != "" {
		e.Service = pb.String(event.Service)
	}

	if event.State != "" {
		e.State = pb.String(event.State)
	}

	if event.Description != "" {
		e.Description = pb.String(event.Description)
	}

	e.Tags = event.Tags

	e.Attributes = sortAttributes(
		event.Attributes,
	)

	if event.TTL != 0 {
		e.Ttl = pb.Float32(float32(event.TTL / time.Second))
	}

	if event.Metric != nil {
		switch reflect.TypeOf(event.Metric).Kind() {
		case reflect.Int, reflect.Int32, reflect.Int64:
			e.MetricSint64 = pb.Int64(reflect.ValueOf(event.Metric).Int())
		case reflect.Float32:
			e.MetricD = pb.Float64(reflect.ValueOf(event.Metric).Float())
		case reflect.Float64:
			e.MetricD = pb.Float64(reflect.ValueOf(event.Metric).Float())
		case reflect.Uint, reflect.Uint32, reflect.Uint64:
			e.MetricSint64 = pb.Int64(int64(reflect.ValueOf(event.Metric).Uint()))
		default:
			return nil, fmt.Errorf("Metric of invalid type (type %v)",
				reflect.TypeOf(event.Metric).Kind())
		}
	}

	return &e, nil
}
57911
func FMSketchToProto(s *FMSketch) *tipb.FMSketch {
	protoSketch := new(tipb.FMSketch)
	protoSketch.Mask = s.mask
	for val := range s.hashset {
		protoSketch.Hashset = append(protoSketch.Hashset, val)
	}
	return protoSketch
}
1171292
func (o TopImagesOptions) imagesTop() []Info {
	g := genericgraph.New()
	addImagesToGraph(g, o.Images)
	addImageStreamsToGraph(g, o.Streams)
	addPodsToGraph(g, o.Pods)
	markParentsInGraph(g)

	infos := []Info{}
	imageNodes := getImageNodes(g.Nodes())
	for _, in := range imageNodes {
		image := in.Image
		istags := getImageStreamTags(g, in)
		parents := getImageParents(g, in)
		usage := getImageUsage(g, in)
		metadata := len(image.DockerImageManifest) != 0 && len(image.DockerImageLayers) != 0
		storage := getStorage(image)
		infos = append(infos, imageInfo{
			Image:           image.Name,
			ImageStreamTags: istags,
			Parents:         parents,
			Usage:           usage,
			Metadata:        metadata,
			Storage:         storage,
		})
	}
	sort.Slice(infos, func(i, j int) bool {
		a, b := infos[i].(imageInfo), infos[j].(imageInfo)
		if len(a.ImageStreamTags) < len(b.ImageStreamTags) {
			return false
		}
		if len(a.ImageStreamTags) > len(b.ImageStreamTags) {
			return true
		}
		return a.Storage > b.Storage
	})

	return infos
}
1316094
func (s *Scan) ToProto() proto.Message {
	scan := &pb.ScanRequest{
		Region:       s.regionSpecifier(),
		CloseScanner: &s.closeScanner,
		NumberOfRows: &s.numberOfRows,
		// tell server that we can process results that are only part of a row
		ClientHandlesPartials: proto.Bool(true),
		// tell server that we "handle" heartbeats by ignoring them
		// since we don't really time out our scans (unless context was cancelled)
		ClientHandlesHeartbeats: proto.Bool(true),
	}
	if s.scannerID != math.MaxUint64 {
		scan.ScannerId = &s.scannerID
		return scan
	}
	scan.Scan = &pb.Scan{
		Column:        familiesToColumn(s.families),
		StartRow:      s.startRow,
		StopRow:       s.stopRow,
		TimeRange:     &pb.TimeRange{},
		MaxResultSize: &s.maxResultSize,
	}
	if s.maxVersions != DefaultMaxVersions {
		scan.Scan.MaxVersions = &s.maxVersions
	}

	/* added support for limit number of cells per row */
	if s.storeLimit != DefaultMaxResultsPerColumnFamily {
		scan.Scan.StoreLimit = &s.storeLimit
	}
	if s.storeOffset != 0 {
		scan.Scan.StoreOffset = &s.storeOffset
	}

	if s.fromTimestamp != MinTimestamp {
		scan.Scan.TimeRange.From = &s.fromTimestamp
	}
	if s.toTimestamp != MaxTimestamp {
		scan.Scan.TimeRange.To = &s.toTimestamp
	}
	if s.reversed {
		scan.Scan.Reversed = &s.reversed
	}
	scan.Scan.Filter = s.filter
	return scan
}
6672
func (ps *GetProcedureState) ToProto() proto.Message {
	return &pb.GetProcedureResultRequest{ProcId: &ps.procID}
}
724419
func (cp *CheckAndPut) ToProto() proto.Message {
	mutateRequest := cp.toProto()
	mutateRequest.Condition = &pb.Condition{
		Row:         cp.key,
		Family:      cp.family,
		Qualifier:   cp.qualifier,
		CompareType: pb.CompareType_EQUAL.Enum(),
		Comparator:  cp.comparator,
	}
	return mutateRequest
}
401759
func toProtoMetric(mt Metric) (*rpc.Metric, error) {
	if mt.Timestamp == (time.Time{}) {
		//Timestamp is unitialized, set to time.Now()
		mt.Timestamp = time.Now()
	}

	if mt.lastAdvertisedTime == (time.Time{}) {
		// lastAdvertisedTime is unitialized, set to time.Now()
		mt.lastAdvertisedTime = time.Now()
	}
	metric := &rpc.Metric{
		Namespace:   toProtoNamespace(mt.Namespace),
		Version:     mt.Version,
		Tags:        mt.Tags,
		Unit:        mt.Unit,
		Description: mt.Description,
		Config:      toProtoConfig(mt.Config),
		Timestamp: &rpc.Time{
			Sec:  mt.Timestamp.Unix(),
			Nsec: int64(mt.Timestamp.Nanosecond()),
		},
		LastAdvertisedTime: &rpc.Time{
			Sec:  mt.lastAdvertisedTime.Unix(),
			Nsec: int64(mt.lastAdvertisedTime.Nanosecond()),
		},
	}
	switch t := mt.Data.(type) {
	case string:
		metric.Data = &rpc.Metric_StringData{StringData: t}
	case float64:
		metric.Data = &rpc.Metric_Float64Data{Float64Data: t}
	case float32:
		metric.Data = &rpc.Metric_Float32Data{Float32Data: t}
	case int32:
		metric.Data = &rpc.Metric_Int32Data{Int32Data: t}
	case int:
		metric.Data = &rpc.Metric_Int64Data{Int64Data: int64(t)}
	case int64:
		metric.Data = &rpc.Metric_Int64Data{Int64Data: t}
	case uint32:
		metric.Data = &rpc.Metric_Uint32Data{Uint32Data: t}
	case uint64:
		metric.Data = &rpc.Metric_Uint64Data{Uint64Data: t}
	case []byte:
		metric.Data = &rpc.Metric_BytesData{BytesData: t}
	case bool:
		metric.Data = &rpc.Metric_BoolData{BoolData: t}
	case nil:
		metric.Data = nil
	default:
		return nil, fmt.Errorf("unsupported type: %s given in metric data", t)
	}
	return metric, nil
}
405640
func ToProtoMsgChan(ch chan ProtoMessage, opts ...interface{}) func(ProtoMessage) {

	timeout, logger := ParseOpts(opts...)

	return func(msg ProtoMessage) {
		select {
		case ch <- msg:
		case <-time.After(timeout):
			logger.Warn("Unable to deliver message")
		}
	}
}
777326
func (et *EnableTable) ToProto() proto.Message {
	return &pb.EnableTableRequest{
		TableName: &pb.TableName{
			// TODO: handle namespaces
			Namespace: []byte("default"),
			Qualifier: et.table,
		},
	}
}
744331
func (s PrefetchStatus) ToProtocolStatus() keybase1.PrefetchStatus {
	switch s {
	case NoPrefetch:
		return keybase1.PrefetchStatus_NOT_STARTED
	case TriggeredPrefetch:
		return keybase1.PrefetchStatus_IN_PROGRESS
	case FinishedPrefetch:
		return keybase1.PrefetchStatus_COMPLETE
	default:
		panic(fmt.Sprintf("Unknown prefetch status: %s", s))
	}
}
1105944
func TimeFromProto(t *timestamp.Timestamp) time.Time {
	if t == nil {
		return time.Time{}
	}
	return time.Unix(t.Seconds, int64(t.Nanos)).UTC()
}
1302119
func (c *Client) TopContainer(id string, psArgs string) (TopResult, error) {
	var args string
	var result TopResult
	if psArgs != "" {
		args = fmt.Sprintf("?ps_args=%s", psArgs)
	}
	path := fmt.Sprintf("/containers/%s/top%s", id, args)
	resp, err := c.do("GET", path, doOptions{})
	if err != nil {
		if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
			return result, &NoSuchContainer{ID: id}
		}
		return result, err
	}
	defer resp.Body.Close()
	err = json.NewDecoder(resp.Body).Decode(&result)
	return result, err
}
367108
func (p *PhysicalIndexScan) ToPB(ctx sessionctx.Context) (*tipb.Executor, error) {
	columns := make([]*model.ColumnInfo, 0, p.schema.Len())
	tableColumns := p.Table.Cols()
	for _, col := range p.schema.Columns {
		if col.ID == model.ExtraHandleID {
			columns = append(columns, model.NewExtraHandleColInfo())
		} else {
			columns = append(columns, model.FindColumnInfo(tableColumns, col.ColName.L))
		}
	}
	idxExec := &tipb.IndexScan{
		TableId: p.Table.ID,
		IndexId: p.Index.ID,
		Columns: model.ColumnsToProto(columns, p.Table.PKIsHandle),
		Desc:    p.Desc,
	}
	unique := checkCoverIndex(p.Index, p.Ranges)
	idxExec.Unique = &unique
	return &tipb.Executor{Tp: tipb.ExecType_TypeIndexScan, IdxScan: idxExec}, nil
}