本文整理匯總了Golang中github.com/gogo/protobuf/proto.Float64函數的典型用法代碼示例。如果您正苦於以下問題:Golang Float64函數的具體用法?Golang Float64怎麽用?Golang Float64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Float64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BuildEmptyResources
// BuildEmptyResources build empty resources
func BuildEmptyResources() []*mesosproto.Resource {
var resources = []*mesosproto.Resource{}
resources = append(resources, &mesosproto.Resource{
Name: proto.String("cpus"),
Type: mesosproto.Value_SCALAR.Enum(),
Scalar: &mesosproto.Value_Scalar{Value: proto.Float64(minCpus)},
})
resources = append(resources, &mesosproto.Resource{
Name: proto.String("mem"),
Type: mesosproto.Value_SCALAR.Enum(),
Scalar: &mesosproto.Value_Scalar{Value: proto.Float64(minMem)},
})
return resources
}
示例2: makeStatusUpdate
func (driver *MesosExecutorDriver) makeStatusUpdate(taskStatus *mesosproto.TaskStatus) *mesosproto.StatusUpdate {
now := float64(time.Now().Unix())
// Fill in all the fields.
taskStatus.Timestamp = proto.Float64(now)
taskStatus.SlaveId = driver.slaveID
update := &mesosproto.StatusUpdate{
FrameworkId: driver.frameworkID,
ExecutorId: driver.executorID,
SlaveId: driver.slaveID,
Status: taskStatus,
Timestamp: proto.Float64(now),
Uuid: uuid.NewUUID(),
}
return update
}
示例3: BuildBasicResources
// BuildBasicResources build basic resources
// including cpus, mem, disk, ports
func BuildBasicResources(task *registry.Task) {
if task.Build {
return
}
if task.Cpus > 0 {
task.Resources = append(task.Resources, &mesosproto.Resource{
Name: proto.String("cpus"),
Type: mesosproto.Value_SCALAR.Enum(),
Scalar: &mesosproto.Value_Scalar{Value: proto.Float64(task.Cpus)},
})
}
if task.Mem > 0 {
task.Resources = append(task.Resources, &mesosproto.Resource{
Name: proto.String("mem"),
Type: mesosproto.Value_SCALAR.Enum(),
Scalar: &mesosproto.Value_Scalar{Value: proto.Float64(task.Mem)},
})
}
if task.Disk > 0 {
task.Resources = append(task.Resources, &mesosproto.Resource{
Name: proto.String("disk"),
Type: mesosproto.Value_SCALAR.Enum(),
Scalar: &mesosproto.Value_Scalar{Value: proto.Float64(task.Disk)},
})
}
if len(task.Ports) > 0 {
ranges := &mesosproto.Value_Ranges{}
for _, port := range task.Ports {
if port.HostPort == 0 {
continue
}
ranges.Range = append(ranges.Range, &mesosproto.Value_Range{
Begin: proto.Uint64(uint64(port.HostPort)),
End: proto.Uint64(uint64(port.HostPort)),
})
}
task.Resources = append(task.Resources, &mesosproto.Resource{
Name: proto.String("ports"),
Type: mesosproto.Value_RANGES.Enum(),
Ranges: ranges,
})
}
task.Build = true
}
示例4: ResourceOffers
func (sched *Scheduler) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) {
logOffers(offers)
jobs, err := getLaunchableJobs()
if err != nil {
log.Errorf("Unable to get pending jobs! %s\n", err.Error())
return
}
offersAndTasks, err := packJobsInOffers(jobs, offers)
if err != nil {
log.Errorf("Unable to pack jobs into offers! %s\n", err.Error())
return
}
for _, ot := range offersAndTasks {
if len(ot.Tasks) == 0 {
log.Infof("Declining unused offer %s", ot.Offer.Id.GetValue())
driver.DeclineOffer(ot.Offer.Id, &mesos.Filters{RefuseSeconds: proto.Float64(1)})
continue
} else {
log.Infof("Launching %d tasks for offer %s\n", len(ot.Tasks), ot.Offer.Id.GetValue())
driver.LaunchTasks([]*mesos.OfferID{ot.Offer.Id}, ot.Tasks, &mesos.Filters{RefuseSeconds: proto.Float64(1)})
sched.tasksLaunched = sched.tasksLaunched + len(ot.Tasks)
}
}
}
示例5: TestUnmarshalPartiallyPopulatedOptionalFieldsFails
func TestUnmarshalPartiallyPopulatedOptionalFieldsFails(t *testing.T) {
// Fill in all fields, then randomly remove one.
dataOut := &test.NinOptNative{
Field1: proto.Float64(0),
Field2: proto.Float32(0),
Field3: proto.Int32(0),
Field4: proto.Int64(0),
Field5: proto.Uint32(0),
Field6: proto.Uint64(0),
Field7: proto.Int32(0),
Field8: proto.Int64(0),
Field9: proto.Uint32(0),
Field10: proto.Int32(0),
Field11: proto.Uint64(0),
Field12: proto.Int64(0),
Field13: proto.Bool(false),
Field14: proto.String("0"),
Field15: []byte("0"),
}
r := rand.New(rand.NewSource(time.Now().UnixNano()))
fieldName := "Field" + strconv.Itoa(r.Intn(15)+1)
field := reflect.ValueOf(dataOut).Elem().FieldByName(fieldName)
fieldType := field.Type()
field.Set(reflect.Zero(fieldType))
encodedMessage, err := proto.Marshal(dataOut)
if err != nil {
t.Fatalf("Unexpected error when marshalling dataOut: %v", err)
}
dataIn := NidOptNative{}
err = proto.Unmarshal(encodedMessage, &dataIn)
if err.Error() != `proto: required field "`+fieldName+`" not set` {
t.Fatalf(`err.Error() != "proto: required field "`+fieldName+`" not set"; was "%s" instead`, err.Error())
}
}
示例6: encodeAux
func encodeAux(aux []interface{}) []*internal.Aux {
pb := make([]*internal.Aux, len(aux))
for i := range aux {
switch v := aux[i].(type) {
case float64:
pb[i] = &internal.Aux{DataType: proto.Int32(Float), FloatValue: proto.Float64(v)}
case *float64:
pb[i] = &internal.Aux{DataType: proto.Int32(Float)}
case int64:
pb[i] = &internal.Aux{DataType: proto.Int32(Integer), IntegerValue: proto.Int64(v)}
case *int64:
pb[i] = &internal.Aux{DataType: proto.Int32(Integer)}
case string:
pb[i] = &internal.Aux{DataType: proto.Int32(String), StringValue: proto.String(v)}
case *string:
pb[i] = &internal.Aux{DataType: proto.Int32(String)}
case bool:
pb[i] = &internal.Aux{DataType: proto.Int32(Boolean), BooleanValue: proto.Bool(v)}
case *bool:
pb[i] = &internal.Aux{DataType: proto.Int32(Boolean)}
default:
pb[i] = &internal.Aux{DataType: proto.Int32(int32(Unknown))}
}
}
return pb
}
示例7: newScalarAttribute
func newScalarAttribute(name string, val float64) *mesos.Attribute {
return &mesos.Attribute{
Name: proto.String(name),
Type: mesos.Value_SCALAR.Enum(),
Scalar: &mesos.Value_Scalar{Value: proto.Float64(val)},
}
}
示例8: basicValueMetric
func basicValueMetric(name string, value float64, unit string) *events.ValueMetric {
return &events.ValueMetric{
Name: proto.String(name),
Value: proto.Float64(value),
Unit: proto.String(unit),
}
}
示例9: TestGetExtensionStability
//See another version of this test in proto/extensions_test.go
func TestGetExtensionStability(t *testing.T) {
check := func(m *NoExtensionsMap) bool {
ext1, err := proto.GetExtension(m, E_FieldB1)
if err != nil {
t.Fatalf("GetExtension() failed: %s", err)
}
ext2, err := proto.GetExtension(m, E_FieldB1)
if err != nil {
t.Fatalf("GetExtension() failed: %s", err)
}
return ext1.(*NinOptNative).Equal(ext2)
}
msg := &NoExtensionsMap{Field1: proto.Int64(2)}
ext0 := &NinOptNative{Field1: proto.Float64(1)}
if err := proto.SetExtension(msg, E_FieldB1, ext0); err != nil {
t.Fatalf("Could not set ext1: %s", ext0)
}
if !check(msg) {
t.Errorf("GetExtension() not stable before marshaling")
}
bb, err := proto.Marshal(msg)
if err != nil {
t.Fatalf("Marshal() failed: %s", err)
}
msg1 := &NoExtensionsMap{}
err = proto.Unmarshal(bb, msg1)
if err != nil {
t.Fatalf("Unmarshal() failed: %s", err)
}
if !check(msg1) {
t.Errorf("GetExtension() not stable after unmarshaling")
}
}
示例10: NewScalarResource
func NewScalarResource(name string, val float64) *mesos.Resource {
return &mesos.Resource{
Name: proto.String(name),
Type: mesos.Value_SCALAR.Enum(),
Scalar: &mesos.Value_Scalar{Value: proto.Float64(val)},
}
}
示例11: NewDoubleConst
//NewDoubleConst returns a new terminal expression containing the given double value.
// double(d)
func NewDoubleConst(d float64) *Expr {
return &Expr{
Terminal: &Terminal{
DoubleValue: proto.Float64(d),
},
}
}
示例12: TestExtend
func TestExtend(t *testing.T) {
fp, err := fieldpath.NewFloat64Path("test", "MyExtendable", test.ThetestDescription(), "FieldA")
if err != nil {
panic(err)
}
m := &test.MyExtendable{}
err = proto.SetExtension(m, test.E_FieldA, proto.Float64(10.0))
if err != nil {
panic(err)
}
buf, err := proto.Marshal(m)
if err != nil {
panic(err)
}
var unmarshalled float64
f := FuncHandler{
Float64Func: func(v float64) {
t.Logf("unmarshalled %v", v)
unmarshalled = v
},
}
unmarshaler := fieldpath.NewFloat64Unmarshaler(fp, f)
err = unmarshaler.Unmarshal(buf)
if err != nil {
panic(err)
}
if unmarshalled != float64(10.0) {
panic(fmt.Errorf("wtf %v", unmarshalled))
}
}
示例13: writeValueMessage
func writeValueMessage(port int) {
conn, err := net.Dial("udp", fmt.Sprintf("localhost:%d", port))
Expect(err).ToNot(HaveOccurred())
message := &events.Envelope{
EventType: events.Envelope_ValueMetric.Enum(),
Origin: proto.String("someorigin"),
ValueMetric: &events.ValueMetric{
Name: proto.String("some name"),
Value: proto.Float64(24.0),
Unit: proto.String("some unit"),
},
}
messageBytes, err := proto.Marshal(message)
Expect(err).ToNot(HaveOccurred())
// Pad the first 32 bytes of the payload with zeroes
// In reality this would be the signature
padding := make([]byte, 32)
payload := append(padding, messageBytes...)
conn.Write(payload)
}
示例14: NewStatusUpdate
func NewStatusUpdate(frameworkId *mesos.FrameworkID, taskStatus *mesos.TaskStatus, timestamp float64, uuid []byte) *mesos.StatusUpdate {
return &mesos.StatusUpdate{
FrameworkId: frameworkId,
Status: taskStatus,
Timestamp: proto.Float64(timestamp),
Uuid: uuid,
}
}
示例15: sendEventsThroughFirehose
func sendEventsThroughFirehose(fakeFirehoseInputChan chan *events.Envelope) {
fakeFirehoseInputChan <- &events.Envelope{
Origin: proto.String("origin"),
Timestamp: proto.Int64(1000000000),
EventType: events.Envelope_ValueMetric.Enum(),
ValueMetric: &events.ValueMetric{
Name: proto.String("metricName"),
Value: proto.Float64(5),
Unit: proto.String("gauge"),
},
Deployment: proto.String("deployment-name"),
Job: proto.String("doppler"),
Index: proto.String("SOME-METRIC-GUID"),
}
fakeFirehoseInputChan <- &events.Envelope{
Origin: proto.String("origin"),
Timestamp: proto.Int64(2000000000),
EventType: events.Envelope_ValueMetric.Enum(),
ValueMetric: &events.ValueMetric{
Name: proto.String("metricName"),
Value: proto.Float64(10),
Unit: proto.String("gauge"),
},
Deployment: proto.String("deployment-name"),
Job: proto.String("gorouter"),
Index: proto.String("SOME-METRIC-GUID-2"),
}
fakeFirehoseInputChan <- &events.Envelope{
Origin: proto.String("origin"),
Timestamp: proto.Int64(3000000000),
EventType: events.Envelope_CounterEvent.Enum(),
CounterEvent: &events.CounterEvent{
Name: proto.String("counterName"),
Delta: proto.Uint64(3),
Total: proto.Uint64(15),
},
Deployment: proto.String("deployment-name"),
Job: proto.String("doppler"),
Index: proto.String("SOME-METRIC-GUID-3"),
}
close(fakeFirehoseInputChan)
}
開發者ID:pivotal-cf-experimental,項目名稱:opentsdb-firehose-nozzle,代碼行數:45,代碼來源:opentsdb_firehose_nozzle_test.go