// EcpToProto converts a *amcl.ECP into the proto struct *ECP
430154
func EcpToProto(p *FP256BN.ECP) *ECP {
	return &ECP{
		X: BigToBytes(p.GetX()),
		Y: BigToBytes(p.GetY())}
}
78066
func CMSketchFromProto(protoSketch *tipb.CMSketch) *CMSketch {
	if protoSketch == nil {
		return nil
	}
	c := NewCMSketch(int32(len(protoSketch.Rows)), int32(len(protoSketch.Rows[0].Counters)))
	for i, row := range protoSketch.Rows {
		c.count = 0
		for j, counter := range row.Counters {
			c.table[i][j] = counter
			c.count = c.count + uint64(counter)
		}
	}
	if len(protoSketch.TopN) == 0 {
		return c
	}
	c.defaultValue = protoSketch.DefaultValue
	c.topN = make(map[uint64][]*TopNMeta)
	for _, e := range protoSketch.TopN {
		h1, h2 := murmur3.Sum128(e.Data)
		c.topN[h1] = append(c.topN[h1], &TopNMeta{h2, e.Data, e.Count})
	}
	return c
}
114002
func (c *channel) pubMsgToMsgProto(pm *pb.PubMsg, seq uint64) *pb.MsgProto {
	m := &pb.MsgProto{
		Sequence:  seq,
		Subject:   pm.Subject,
		Reply:     pm.Reply,
		Data:      pm.Data,
		Timestamp: time.Now().UnixNano(),
	}
	if c.lTimestamp > 0 && m.Timestamp < c.lTimestamp {
		m.Timestamp = c.lTimestamp
	}
	c.lTimestamp = m.Timestamp
	return m
}
18426
func TimeToProto(t time.Time) *logutilpb.Time {
	seconds := t.Unix()
	nanos := int64(t.Sub(time.Unix(seconds, 0)))
	return &logutilpb.Time{
		Seconds:     seconds,
		Nanoseconds: int32(nanos),
	}
}
936684
func toProto(resource Resource) *pb.Resource {
	b := &pb.Resource{
		Path: []string{resource.Path()},
		Mode: uint32(resource.Mode()),
		Uid:  resource.UID(),
		Gid:  resource.GID(),
	}

	if xattrer, ok := resource.(XAttrer); ok {
		// Sorts the XAttrs by name for consistent ordering.
		keys := []string{}
		xattrs := xattrer.XAttrs()
		for k := range xattrs {
			keys = append(keys, k)
		}
		sort.Strings(keys)

		for _, k := range keys {
			b.Xattr = append(b.Xattr, &pb.XAttr{Name: k, Data: xattrs[k]})
		}
	}

	switch r := resource.(type) {
	case RegularFile:
		b.Path = r.Paths()
		b.Size = uint64(r.Size())

		for _, dgst := range r.Digests() {
			b.Digest = append(b.Digest, dgst.String())
		}
	case SymLink:
		b.Target = r.Target()
	case Device:
		b.Major, b.Minor = r.Major(), r.Minor()
		b.Path = r.Paths()
	case NamedPipe:
		b.Path = r.Paths()
	}

	// enforce a few stability guarantees that may not be provided by the
	// resource implementation.
	sort.Strings(b.Path)

	return b
}
731164
func xpcToGo(v C.xpc_object_t) interface{} {
	t := C.xpc_get_type(v)

	switch t {
	case C.TYPE_ARRAY:
		a := make(Array, C.int(C.xpc_array_get_count(v)))
		C.XpcArrayApply(unsafe.Pointer(&a), v)
		return a

	case C.TYPE_DATA:
		return C.GoBytes(C.xpc_data_get_bytes_ptr(v), C.int(C.xpc_data_get_length(v)))

	case C.TYPE_DICT:
		d := make(Dict)
		C.XpcDictApply(unsafe.Pointer(&d), v)
		return d

	case C.TYPE_INT64:
		return int64(C.xpc_int64_get_value(v))

	case C.TYPE_STRING:
		return C.GoString(C.xpc_string_get_string_ptr(v))

	case C.TYPE_UUID:
		a := [16]byte{}
		C.XpcUUIDGetBytes(unsafe.Pointer(&a), v)
		return UUID(a[:])

	default:
		log.Fatalf("unexpected type %#v, value %#v", t, v)
	}

	return nil
}
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),
	}
}
1028738
func (u *Ugen) Amclip(val Input) Input {
	return binOpAmclip(u.Rate, u, val, u.NumOutputs)
}
900212
func stateToProto(state PluginState) status.OperationalState {
	switch state {
	case Init:
		return status.OperationalState_INIT
	case OK:
		return status.OperationalState_OK
	default:
		return status.OperationalState_ERROR
	}
}
65326
func HistogramFromProto(protoHg *tipb.Histogram) *Histogram {
	tp := types.NewFieldType(mysql.TypeBlob)
	hg := NewHistogram(0, protoHg.Ndv, 0, 0, tp, len(protoHg.Buckets), 0)
	for _, bucket := range protoHg.Buckets {
		lower, upper := types.NewBytesDatum(bucket.LowerBound), types.NewBytesDatum(bucket.UpperBound)
		hg.AppendBucket(&lower, &upper, bucket.Count, bucket.Repeats)
	}
	return hg
}
776098
func Mgo(resultPtr interface{}, operate string, option map[string]interface{}) error {
	o := getOperator(operate)
	if o == nil {
		return errors.New("the db-operate " + operate + " does not exist!")
	}

	v := reflect.ValueOf(o).Elem()
	for key, val := range option {
		value := v.FieldByName(key)
		if value == (reflect.Value{}) || !value.CanSet() {
			continue
		}
		value.Set(reflect.ValueOf(val))
	}

	return o.Exec(resultPtr)
}
6672
func (ps *GetProcedureState) ToProto() proto.Message {
	return &pb.GetProcedureResultRequest{ProcId: &ps.procID}
}
1166885
func SampleCollectorToProto(c *SampleCollector) *tipb.SampleCollector {
	collector := &tipb.SampleCollector{
		NullCount: c.NullCount,
		Count:     c.Count,
		FmSketch:  FMSketchToProto(c.FMSketch),
		TotalSize: &c.TotalSize,
	}
	if c.CMSketch != nil {
		collector.CmSketch = CMSketchToProto(c.CMSketch)
	}
	for _, item := range c.Samples {
		collector.Samples = append(collector.Samples, item.Value.GetBytes())
	}
	return collector
}
1100893
func FromProto(s *rpc.Status) *Status {
	return &Status{s: proto.Clone(s).(*rpc.Status)}
}
209362
func isTypeApplicableToProtobuf(t *types.Type) bool {
	// skip functions -- we don't care about them for protobuf
	if t.Kind == types.Func || (t.Kind == types.DeclarationOf && t.Underlying.Kind == types.Func) {
		return false
	}
	// skip private types
	if namer.IsPrivateGoName(t.Name.Name) {
		return false
	}

	return true
}
91514
func ConfigSchemaToProto(b *configschema.Block) *proto.Schema_Block {
	block := &proto.Schema_Block{}

	for _, name := range sortedKeys(b.Attributes) {
		a := b.Attributes[name]
		attr := &proto.Schema_Attribute{
			Name:        name,
			Description: a.Description,
			Optional:    a.Optional,
			Computed:    a.Computed,
			Required:    a.Required,
			Sensitive:   a.Sensitive,
		}

		ty, err := json.Marshal(a.Type)
		if err != nil {
			panic(err)
		}

		attr.Type = ty

		block.Attributes = append(block.Attributes, attr)
	}

	for _, name := range sortedKeys(b.BlockTypes) {
		b := b.BlockTypes[name]
		block.BlockTypes = append(block.BlockTypes, protoSchemaNestedBlock(name, b))
	}

	return block
}