// ToProto converts the RPC into a protobuf message
777326
func (et *EnableTable) ToProto() proto.Message {
	return &pb.EnableTableRequest{
		TableName: &pb.TableName{
			// TODO: handle namespaces
			Namespace: []byte("default"),
			Qualifier: et.table,
		},
	}
}
404715
func (iampb *IAMPrincipalBuilder) ToPrivilege() sparta.IAMRolePrivilege {
	privilege := sparta.IAMRolePrivilege{
		Actions:   iampb.builder.apiCalls,
		Principal: iampb.principal,
	}
	if iampb.builder.condition != nil {
		privilege.Condition = iampb.builder.condition
	}
	return privilege
}
347864
func (p *TypeSetterPrinter) ToPrinter(delegate ResourcePrinter) ResourcePrinter {
	if p == nil {
		return delegate
	}

	p.Delegate = delegate
	return p
}
1105944
func TimeFromProto(t *timestamp.Timestamp) time.Time {
	if t == nil {
		return time.Time{}
	}
	return time.Unix(t.Seconds, int64(t.Nanos)).UTC()
}
772323
func (f *PrintFlags) ToPrinter() (printers.ResourcePrinter, error) {
	outputFormat := ""
	if f.OutputFormat != nil {
		outputFormat = *f.OutputFormat
	}

	noHeaders := false
	if f.NoHeaders != nil {
		noHeaders = *f.NoHeaders
	}
	f.HumanReadableFlags.NoHeaders = noHeaders
	f.CustomColumnsFlags.NoHeaders = noHeaders

	// for "get.go" we want to support a --template argument given, even when no --output format is provided
	if f.TemplateFlags.TemplateArgument != nil && len(*f.TemplateFlags.TemplateArgument) > 0 && len(outputFormat) == 0 {
		outputFormat = "go-template"
	}

	if p, err := f.TemplateFlags.ToPrinter(outputFormat); !genericclioptions.IsNoCompatiblePrinterError(err) {
		return p, err
	}

	if f.TemplateFlags.TemplateArgument != nil {
		f.CustomColumnsFlags.TemplateArgument = *f.TemplateFlags.TemplateArgument
	}

	if p, err := f.JSONYamlPrintFlags.ToPrinter(outputFormat); !genericclioptions.IsNoCompatiblePrinterError(err) {
		return p, err
	}

	if p, err := f.HumanReadableFlags.ToPrinter(outputFormat); !genericclioptions.IsNoCompatiblePrinterError(err) {
		return p, err
	}

	if p, err := f.CustomColumnsFlags.ToPrinter(outputFormat); !genericclioptions.IsNoCompatiblePrinterError(err) {
		return p, err
	}

	if p, err := f.NamePrintFlags.ToPrinter(outputFormat); !genericclioptions.IsNoCompatiblePrinterError(err) {
		return p, err
	}

	return nil, genericclioptions.NoCompatiblePrinterError{OutputFormat: &outputFormat, AllowedFormats: f.AllowedFormats()}
}
726076
func ResultsToProto3(qr []Result) []*querypb.QueryResult {
	if len(qr) == 0 {
		return nil
	}
	result := make([]*querypb.QueryResult, len(qr))
	for i, q := range qr {
		result[i] = ResultToProto3(&q)
	}
	return result
}
1321383
func (d Device) ToPb() *pb_handler.Device {
	return &pb_handler.Device{
		AppID:       d.AppID,
		DevID:       d.DevID,
		Description: d.Description,
		Device:      &pb_handler.Device_LoRaWANDevice{LoRaWANDevice: d.ToLoRaWANPb()},
		Latitude:    d.Latitude,
		Longitude:   d.Longitude,
		Altitude:    d.Altitude,
		Attributes:  d.Attributes,
	}
}
639254
func (p *PhysicalSelection) ToPB(ctx sessionctx.Context) (*tipb.Executor, error) {
	sc := ctx.GetSessionVars().StmtCtx
	client := ctx.GetClient()
	selExec := &tipb.Selection{
		Conditions: expression.ExpressionsToPBList(sc, p.Conditions, client),
	}
	return &tipb.Executor{Tp: tipb.ExecType_TypeSelection, Selection: selExec}, nil
}
289220
func QueryResponsesToProto3(qr []QueryResponse) []*querypb.ResultWithError {
	if len(qr) == 0 {
		return nil
	}
	result := make([]*querypb.ResultWithError, len(qr))
	for i, q := range qr {
		result[i] = &querypb.ResultWithError{
			Result: ResultToProto3(q.QueryResult),
			Error:  vterrors.ToVTRPC(q.QueryError),
		}
	}
	return result
}
1185688
func ToChanProto(respCh chan datasync.ProtoWatchResp, opts ...interface{}) func(dto datasync.ProtoWatchResp) {
	return func(dto datasync.ProtoWatchResp) {
		select {
		case respCh <- dto:
			// success
		case <-time.After(datasync.DefaultNotifTimeout):
			logging.DefaultLogger.Warn("Unable to deliver notification")
		}
	}
}
874361
func HistogramToProto(hg *Histogram) *tipb.Histogram {
	protoHg := &tipb.Histogram{
		Ndv: hg.NDV,
	}
	for i := 0; i < hg.Len(); i++ {
		bkt := &tipb.Bucket{
			Count:      hg.Buckets[i].Count,
			LowerBound: hg.GetLower(i).GetBytes(),
			UpperBound: hg.GetUpper(i).GetBytes(),
			Repeats:    hg.Buckets[i].Repeat,
		}
		protoHg.Buckets = append(protoHg.Buckets, bkt)
	}
	return protoHg
}
590152
func protoToJSON(msg proto.Message) ([]byte, error) {
	if reflect.ValueOf(msg).IsNil() {
		panic("We're nil here")
	}
	var b bytes.Buffer
	m := jsonpb.Marshaler{
		EnumsAsInts:  false,
		EmitDefaults: true,
		Indent:       "  ",
		OrigName:     true,
	}
	err := m.Marshal(&b, msg)
	if err != nil {
		return nil, err
	}
	return b.Bytes(), nil
}
588353
func ToProtoMsgErrChan(ch chan ProtoMessageErr, opts ...interface{}) func(ProtoMessageErr) {

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

	return func(msg ProtoMessageErr) {
		select {
		case ch <- msg:
		case <-time.After(timeout):
			logger.Warn("Unable to deliver message")
		}
	}
}
340734
func (m *Mrb) TopSelf() *MrbValue {
	return newValue(m.state, C.mrb_obj_value(unsafe.Pointer(m.state.top_self)))
}
599750
func (g *Get) ToProto() proto.Message {
	get := &pb.GetRequest{
		Region: g.regionSpecifier(),
		Get: &pb.Get{
			Row:       g.key,
			Column:    familiesToColumn(g.families),
			TimeRange: &pb.TimeRange{},
		},
	}

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

	if g.maxVersions != DefaultMaxVersions {
		get.Get.MaxVersions = &g.maxVersions
	}
	if g.fromTimestamp != MinTimestamp {
		get.Get.TimeRange.From = &g.fromTimestamp
	}
	if g.toTimestamp != MaxTimestamp {
		get.Get.TimeRange.To = &g.toTimestamp
	}
	if g.existsOnly {
		get.Get.ExistenceOnly = proto.Bool(true)
	}
	get.Get.Filter = g.filter
	return get
}
905314
func (q *Quest) ToProto() *dm.Quest {
	return &dm.Quest{
		Id:   dm.NewQuestID(q.ID),
		Data: q.DataProto(),
	}
}
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
}