// ToProto returns a dm proto version of this Attempt.
337828
func (a *Attempt) ToProto(withData bool) *dm.Attempt {
	ret := dm.Attempt{Id: &a.ID}
	if withData {
		ret.Data = a.DataProto()
	}
	return &ret
}
196971
func Ecp2ToProto(p *FP256BN.ECP2) *ECP2 {
	return &ECP2{
		Xa: BigToBytes(p.GetX().GetA()),
		Xb: BigToBytes(p.GetX().GetB()),
		Ya: BigToBytes(p.GetY().GetA()),
		Yb: BigToBytes(p.GetY().GetB())}
}
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
}
1089729
func SlaveStatusToProto(s SlaveStatus) *replicationdatapb.Status {
	return &replicationdatapb.Status{
		Position:            EncodePosition(s.Position),
		SlaveIoRunning:      s.SlaveIORunning,
		SlaveSqlRunning:     s.SlaveSQLRunning,
		SecondsBehindMaster: uint32(s.SecondsBehindMaster),
		MasterHost:          s.MasterHost,
		MasterPort:          int32(s.MasterPort),
		MasterConnectRetry:  int32(s.MasterConnectRetry),
	}
}
6672
func (ps *GetProcedureState) ToProto() proto.Message {
	return &pb.GetProcedureResultRequest{ProcId: &ps.procID}
}
991880
func ToProtoEC(ec com_signalfx_metrics_protobuf.EventCategory) Category {
	var response = USERDEFINED
	// Check if the event.Category does not have a corresponding com_signalfx_metrics_protobuf.EventCategory
	if _, ok := com_signalfx_metrics_protobuf.EventCategory_name[int32(ec)]; ok {
		response = Category(int32(ec))
	}
	// Return the com_signalfx_metrics_protobuf.EventCategory
	return response
}
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))
	}
}
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")
		}
	}
}
488102
func (f *NamePrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrinter, error) {
	namePrinter := &printers.NamePrinter{
		Operation: f.Operation,
	}

	outputFormat = strings.ToLower(outputFormat)
	switch outputFormat {
	case "name":
		namePrinter.ShortOutput = true
		fallthrough
	case "":
		return namePrinter, nil
	default:
		return nil, NoCompatiblePrinterError{OutputFormat: &outputFormat, AllowedFormats: f.AllowedFormats()}
	}
}
977763
func (r *Render) toPos(cursor int) (x, y int) {
	col := int(r.col)
	return cursor % col, cursor / col
}
495058
func (m GatewayIDMetadata) ToProto() *pb.Metadata {
	return &pb.Metadata{
		Metadata: &pb.Metadata_GatewayID{
			GatewayID: m.GatewayID,
		},
	}
}
528286
func (m *Message) ToProto() (proto.Message, error) {
	ptr := m.typ.NewProtoMessage() // ~ ptr := &ProtoMessage{}
	msg := ptr.Elem()              // ~ msg := *ptr (a reference)

	for name, val := range m.fields {
		fd, ok := m.typ.fields[name]
		if !ok {
			panic("should not happen, SetField and Attr checks the structure already")
		}
		if err := assign(fd.onProtoReflection(msg, reflectToProto), val); err != nil {
			return nil, fmt.Errorf("bad value for field %q of %q - %s", name, m.Type(), err)
		}
	}

	return ptr.Interface().(proto.Message), nil
}
735014
func (a Announcement) ToProto() *pb.Announcement {
	metadata := make([]*pb.Metadata, 0, len(a.Metadata))
	for _, meta := range a.Metadata {
		metadata = append(metadata, meta.ToProto())
	}
	return &pb.Announcement{
		ID:             a.ID,
		ServiceName:    a.ServiceName,
		ServiceVersion: a.ServiceVersion,
		Description:    a.Description,
		Url:            a.URL,
		Public:         a.Public,
		NetAddress:     a.NetAddress,
		PublicKey:      a.PublicKey,
		Certificate:    a.Certificate,
		ApiAddress:     a.APIAddress,
		MqttAddress:    a.MQTTAddress,
		AmqpAddress:    a.AMQPAddress,
		Metadata:       metadata,
	}
}
741712
func toPropertyDescriptor(rt *_runtime, value Value) (descriptor _property) {
	objectDescriptor := value._object()
	if objectDescriptor == nil {
		panic(rt.panicTypeError())
	}

	{
		descriptor.mode = modeSetMask // Initially nothing is set
		if objectDescriptor.hasProperty("enumerable") {
			if objectDescriptor.get("enumerable").bool() {
				descriptor.enumerateOn()
			} else {
				descriptor.enumerateOff()
			}
		}

		if objectDescriptor.hasProperty("configurable") {
			if objectDescriptor.get("configurable").bool() {
				descriptor.configureOn()
			} else {
				descriptor.configureOff()
			}
		}

		if objectDescriptor.hasProperty("writable") {
			if objectDescriptor.get("writable").bool() {
				descriptor.writeOn()
			} else {
				descriptor.writeOff()
			}
		}
	}

	var getter, setter *_object
	getterSetter := false

	if objectDescriptor.hasProperty("get") {
		value := objectDescriptor.get("get")
		if value.IsDefined() {
			if !value.isCallable() {
				panic(rt.panicTypeError())
			}
			getter = value._object()
			getterSetter = true
		} else {
			getter = &_nilGetSetObject
			getterSetter = true
		}
	}

	if objectDescriptor.hasProperty("set") {
		value := objectDescriptor.get("set")
		if value.IsDefined() {
			if !value.isCallable() {
				panic(rt.panicTypeError())
			}
			setter = value._object()
			getterSetter = true
		} else {
			setter = &_nilGetSetObject
			getterSetter = true
		}
	}

	if getterSetter {
		if descriptor.writeSet() {
			panic(rt.panicTypeError())
		}
		descriptor.value = _propertyGetSet{getter, setter}
	}

	if objectDescriptor.hasProperty("value") {
		if getterSetter {
			panic(rt.panicTypeError())
		}
		descriptor.value = objectDescriptor.get("value")
	}

	return
}
347864
func (p *TypeSetterPrinter) ToPrinter(delegate ResourcePrinter) ResourcePrinter {
	if p == nil {
		return delegate
	}

	p.Delegate = delegate
	return p
}
1130603
func (m *multi) ToProto() proto.Message {
	// aggregate calls per region
	actionsPerReg := map[hrpc.RegionInfo][]*pb.Action{}

	for i, c := range m.calls {
		select {
		case <-c.Context().Done():
			// context has expired, don't bother sending it
			m.calls[i] = nil
			continue
		default:
		}

		msg := c.ToProto()

		a := &pb.Action{
			Index: proto.Uint32(uint32(i) + 1), // +1 because 0 index means there's no index
		}

		switch r := msg.(type) {
		case *pb.GetRequest:
			a.Get = r.Get
		case *pb.MutateRequest:
			a.Mutation = r.Mutation
		default:
			panic(fmt.Sprintf("unsupported call type for Multi: %T", c))
		}

		actionsPerReg[c.Region()] = append(actionsPerReg[c.Region()], a)
	}

	// construct the multi proto
	ra := make([]*pb.RegionAction, len(actionsPerReg))
	m.regions = make([]hrpc.RegionInfo, len(actionsPerReg))

	i := 0
	for r, as := range actionsPerReg {
		ra[i] = &pb.RegionAction{
			Region: &pb.RegionSpecifier{
				Type:  pb.RegionSpecifier_REGION_NAME.Enum(),
				Value: r.Name(),
			},
			Action: as,
		}
		// Track the order of RegionActions,
		// so that we can handle whole region exceptions.
		m.regions[i] = r
		i++
	}
	return &pb.MultiRequest{RegionAction: ra}
}
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
}