本文整理汇总了Golang中github.com/gogo/protobuf/proto.Uint32函数的典型用法代码示例。如果您正苦于以下问题:Golang Uint32函数的具体用法?Golang Uint32怎么用?Golang Uint32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Uint32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewMasterInfo
func NewMasterInfo(id string, ip, port uint32) *mesos.MasterInfo {
return &mesos.MasterInfo{
Id: proto.String(id),
Ip: proto.Uint32(ip),
Port: proto.Uint32(port),
}
}
示例2: 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())
}
}
示例3: sendError
func sendError(socket *zmq.Socket, req *Request, err error) {
// Response envelope
resp := &Response{
Error: &Response_Error{},
}
if req != nil {
resp.UUID = req.UUID
}
// If error is a zrpc error
if zrpcErr, ok := err.(zrpcError); ok {
resp.StatusCode = proto.Uint32(uint32(zrpcErr.GetStatusCode()))
resp.Error.Message = proto.String(zrpcErr.GetMessage())
} else {
// Default to internal error
resp.StatusCode = proto.Uint32(uint32(http.StatusInternalServerError))
resp.Error.Message = proto.String(err.Error())
}
// Encode the response
buf, protoErr := proto.Marshal(resp)
if protoErr != nil {
glog.Error(protoErr)
return
}
// Send the response
if _, err := socket.SendBytes(buf, 0); err != nil {
glog.Error(err)
}
}
示例4: SetBodyChecksum
func SetBodyChecksum(body *TransportBody) {
if body == nil {
return
}
data := body.GetData()
if data == nil {
body.Checksum = proto.Uint32(0)
return
}
body.Checksum = proto.Uint32(crc32.ChecksumIEEE(data))
}
示例5: buildPorts
func buildPorts(task eremetic.Task, offer *mesosproto.Offer) ([]*mesosproto.ContainerInfo_DockerInfo_PortMapping, []*mesosproto.Value_Range) {
var resources []*mesosproto.Value_Range
var mappings []*mesosproto.ContainerInfo_DockerInfo_PortMapping
if len(task.Ports) == 0 {
return mappings, resources
}
leftToAssign := len(task.Ports)
for _, rsrc := range offer.Resources {
if *rsrc.Name != "ports" {
continue
}
for _, rng := range rsrc.Ranges.Range {
if leftToAssign == 0 {
break
}
start, end := *rng.Begin, *rng.Begin
for hport := int(*rng.Begin); hport <= int(*rng.End); hport++ {
if leftToAssign == 0 {
break
}
leftToAssign--
tport := &task.Ports[leftToAssign]
tport.HostPort = uint32(hport)
if tport.ContainerPort == 0 {
tport.ContainerPort = tport.HostPort
}
end = uint64(hport + 1)
mappings = append(mappings, &mesosproto.ContainerInfo_DockerInfo_PortMapping{
ContainerPort: proto.Uint32(tport.ContainerPort),
HostPort: proto.Uint32(tport.HostPort),
Protocol: proto.String(tport.Protocol),
})
}
if start != end {
resources = append(resources, mesosutil.NewValueRange(start, end))
}
}
}
return mappings, resources
}
示例6: TestStandalone_pollerFetched
func TestStandalone_pollerFetched(t *testing.T) {
assert := assert.New(t)
// presence of IP address allows fecher to be called
d := NewStandalone(&mesos.MasterInfo{Ip: proto.Uint32(localhost)})
defer d.Cancel()
fetched := make(chan struct{})
pid := &upid.UPID{
ID: "[email protected]:5050",
Host: "127.0.0.1",
Port: "5050",
}
f := fetcherFunc(func(ctx context.Context, addr string) (*upid.UPID, error) {
defer close(fetched)
assert.Equal("127.0.0.1:5050", addr)
return pid, nil
})
go d.poller(f)
// fetch called
select {
case <-fetched: // expected
case <-time.After(1 * time.Second):
t.Fatalf("expected fetch")
}
// read MasterInfo
select {
case mi := <-d.ch:
assert.Equal(mi, CreateMasterInfo(pid))
case <-time.After(1 * time.Second):
t.Fatalf("expected poller to send master info")
}
}
示例7: encodeBooleanPoint
func encodeBooleanPoint(p *BooleanPoint) *internal.Point {
return &internal.Point{
Name: proto.String(p.Name),
Tags: proto.String(p.Tags.ID()),
Time: proto.Int64(p.Time),
Nil: proto.Bool(p.Nil),
Aux: encodeAux(p.Aux),
Aggregated: proto.Uint32(p.Aggregated),
BooleanValue: proto.Bool(p.Value),
}
}
示例8: marshal
// marshal serializes to a protobuf representation.
func (rpi *RetentionPolicyInfo) marshal() *internal.RetentionPolicyInfo {
pb := &internal.RetentionPolicyInfo{
Name: proto.String(rpi.Name),
ReplicaN: proto.Uint32(uint32(rpi.ReplicaN)),
Duration: proto.Int64(int64(rpi.Duration)),
ShardGroupDuration: proto.Int64(int64(rpi.ShardGroupDuration)),
}
pb.ShardGroups = make([]*internal.ShardGroupInfo, len(rpi.ShardGroups))
for i, sgi := range rpi.ShardGroups {
pb.ShardGroups[i] = sgi.marshal()
}
return pb
}
示例9: marshal
// marshal serializes to a protobuf representation.
func (s *RetentionPolicySpec) marshal() *internal.RetentionPolicySpec {
pb := &internal.RetentionPolicySpec{}
if s.Name != "" {
pb.Name = proto.String(s.Name)
}
if s.Duration != nil {
pb.Duration = proto.Int64(int64(*s.Duration))
}
if s.ShardGroupDuration > 0 {
pb.ShardGroupDuration = proto.Int64(int64(s.ShardGroupDuration))
}
if s.ReplicaN != nil {
pb.ReplicaN = proto.Uint32(uint32(*s.ReplicaN))
}
return pb
}
示例10: main
func main() {
for {
client := NewClient()
if !client.Connect("127.0.0.1:80") {
return
}
retCmd := &usercmd.ReqUserLogin{
Account: proto.String("abcd"),
Password: proto.String("123456"),
Key: proto.Uint32(100),
}
client.SendCmd(usercmd.UserCmd_Login, retCmd)
time.Sleep(time.Millisecond * 1)
}
}
示例11: InitChecksum
// InitChecksum initializes a checksum based on the provided key and
// the contents of the value. If the value contains a byte slice, the
// checksum includes it directly.
func (v *Value) InitChecksum(key []byte) {
if v.Checksum == nil {
v.Checksum = proto.Uint32(v.computeChecksum(key))
}
}
示例12: Build
// Build method builds the task
func (t *Task) Build(slaveID string, offers map[string]*mesosproto.Offer) {
t.Command = &mesosproto.CommandInfo{Shell: proto.Bool(false)}
t.Container = &mesosproto.ContainerInfo{
Type: mesosproto.ContainerInfo_DOCKER.Enum(),
Docker: &mesosproto.ContainerInfo_DockerInfo{
Image: &t.config.Image,
},
}
if t.config.Hostname != "" {
t.Container.Hostname = proto.String(t.config.Hostname)
if t.config.Domainname != "" {
t.Container.Hostname = proto.String(t.config.Hostname + "." + t.config.Domainname)
}
}
switch t.config.HostConfig.NetworkMode {
case "none":
t.Container.Docker.Network = mesosproto.ContainerInfo_DockerInfo_NONE.Enum()
case "host":
t.Container.Docker.Network = mesosproto.ContainerInfo_DockerInfo_HOST.Enum()
case "default", "bridge", "":
var ports []uint64
for _, offer := range offers {
ports = append(ports, getPorts(offer)...)
}
for containerProtoPort, bindings := range t.config.HostConfig.PortBindings {
for _, binding := range bindings {
containerInfo := strings.SplitN(containerProtoPort, "/", 2)
containerPort, err := strconv.ParseUint(containerInfo[0], 10, 32)
if err != nil {
log.Warn(err)
continue
}
var hostPort uint64
if binding.HostPort != "" {
hostPort, err = strconv.ParseUint(binding.HostPort, 10, 32)
if err != nil {
log.Warn(err)
continue
}
} else if len(ports) > 0 {
hostPort = ports[0]
ports = ports[1:]
}
if hostPort == 0 {
log.Warn("cannot find port to bind on the host")
continue
}
protocol := "tcp"
if len(containerInfo) == 2 {
protocol = containerInfo[1]
}
t.Container.Docker.PortMappings = append(t.Container.Docker.PortMappings, &mesosproto.ContainerInfo_DockerInfo_PortMapping{
HostPort: proto.Uint32(uint32(hostPort)),
ContainerPort: proto.Uint32(uint32(containerPort)),
Protocol: proto.String(protocol),
})
t.Resources = append(t.Resources, mesosutil.NewRangesResource("ports", []*mesosproto.Value_Range{mesosutil.NewValueRange(hostPort, hostPort)}))
}
}
// TODO handle -P here
t.Container.Docker.Network = mesosproto.ContainerInfo_DockerInfo_BRIDGE.Enum()
default:
log.Errorf("Unsupported network mode %q", t.config.HostConfig.NetworkMode)
t.Container.Docker.Network = mesosproto.ContainerInfo_DockerInfo_BRIDGE.Enum()
}
if cpus := t.config.CpuShares; cpus > 0 {
t.Resources = append(t.Resources, mesosutil.NewScalarResource("cpus", float64(cpus)))
}
if mem := t.config.Memory; mem > 0 {
t.Resources = append(t.Resources, mesosutil.NewScalarResource("mem", float64(mem/1024/1024)))
}
if len(t.config.Cmd) > 0 && t.config.Cmd[0] != "" {
t.Command.Value = &t.config.Cmd[0]
}
if len(t.config.Cmd) > 1 {
t.Command.Arguments = t.config.Cmd[1:]
}
for key, value := range t.config.Labels {
t.Container.Docker.Parameters = append(t.Container.Docker.Parameters, &mesosproto.Parameter{Key: proto.String("label"), Value: proto.String(fmt.Sprintf("%s=%s", key, value))})
}
for _, value := range t.config.Env {
t.Container.Docker.Parameters = append(t.Container.Docker.Parameters, &mesosproto.Parameter{Key: proto.String("env"), Value: proto.String(value)})
}
//.........这里部分代码省略.........
示例13:
pb "github.com/gogo/protobuf/jsonpb/jsonpb_test_proto"
"github.com/gogo/protobuf/proto"
)
var (
marshaller = Marshaller{}
marshallerAllOptions = Marshaller{
EnumsAsString: true,
Indent: " ",
}
simpleObject = &pb.Simple{
OInt32: proto.Int32(-32),
OInt64: proto.Int64(-6400000000),
OUint32: proto.Uint32(32),
OUint64: proto.Uint64(6400000000),
OSint32: proto.Int32(-13),
OSint64: proto.Int64(-2600000000),
OFloat: proto.Float32(3.14),
ODouble: proto.Float64(6.02214179e23),
OBool: proto.Bool(true),
OString: proto.String("hello \"there\""),
OBytes: []byte("beep boop"),
}
simpleObjectJSON = `{` +
`"o_bool":true,` +
`"o_int32":-32,` +
`"o_int64":"-6400000000",` +
`"o_uint32":32,` +
示例14: TestStandalone_pollerFetchedMulti
func TestStandalone_pollerFetchedMulti(t *testing.T) {
assert := assert.New(t)
// presence of IP address allows fecher to be called
d := NewStandalone(&mesos.MasterInfo{Ip: proto.Uint32(localhost)})
defer d.Cancel()
d.leaderSyncInterval = 500 * time.Millisecond
i := 0
var wg sync.WaitGroup
wg.Add(4)
f := fetcherFunc(func(ctx context.Context, addr string) (*upid.UPID, error) {
defer func() { i++ }()
switch i {
case 0:
wg.Done()
assert.Equal("127.0.0.1:5050", addr)
return &upid.UPID{ID: "[email protected]:5050", Host: "127.0.0.1", Port: "5050"}, nil
case 1:
wg.Done()
assert.Equal("127.0.0.1:5050", addr)
return &upid.UPID{ID: "[email protected]:5050", Host: "127.0.0.2", Port: "5050"}, nil
case 2:
wg.Done()
return nil, context.DeadlineExceeded
case 3:
wg.Done()
assert.Equal("127.0.0.1:5050", addr)
return &upid.UPID{ID: "[email protected]:5050", Host: "127.0.0.3", Port: "5050"}, nil
default:
d.Cancel()
return nil, context.Canceled
}
})
go d.poller(f)
// fetches complete
ch := make(chan struct{})
go func() {
defer close(ch)
wg.Wait()
}()
changed := make(chan struct{})
go func() {
defer close(changed)
for i := 0; i < 4; i++ {
if mi, ok := <-d.ch; !ok {
t.Fatalf("failed to read master info on cycle %v", i)
break
} else {
switch i {
case 0:
assert.Equal(CreateMasterInfo(&upid.UPID{ID: "[email protected]:5050", Host: "127.0.0.1", Port: "5050"}), mi)
case 1:
assert.Equal(CreateMasterInfo(&upid.UPID{ID: "[email protected]:5050", Host: "127.0.0.2", Port: "5050"}), mi)
case 2:
assert.Nil(mi)
case 3:
assert.Equal(CreateMasterInfo(&upid.UPID{ID: "[email protected]:5050", Host: "127.0.0.3", Port: "5050"}), mi)
}
}
}
}()
started := time.Now()
select {
case <-ch: // expected
case <-time.After(3 * time.Second):
t.Fatalf("expected fetches all complete")
}
select {
case <-changed: // expected
case <-time.After((3 * time.Second) - time.Now().Sub(started)):
t.Fatalf("expected to have received all master info changes")
}
}
示例15: launchOne
//.........这里部分代码省略.........
s.mut.Lock()
var clusterType string
if len(s.running) == 0 {
clusterType = "new"
} else {
clusterType = "existing"
}
s.highestInstanceID++
name := "etcd-" + strconv.FormatInt(s.highestInstanceID, 10)
node := &config.Node{
Name: name,
Host: *offer.Hostname,
RPCPort: rpcPort,
ClientPort: clientPort,
ReseedPort: httpPort,
Type: clusterType,
SlaveID: offer.GetSlaveId().GetValue(),
}
running := []*config.Node{node}
for _, r := range s.running {
running = append(running, r)
}
serializedNodes, err := json.Marshal(running)
log.Infof("Serialized running: %+v", string(serializedNodes))
if err != nil {
log.Errorf("Could not serialize running list: %v", err)
// This Unlock is not deferred because the test implementation of LaunchTasks
// calls this scheduler's StatusUpdate method, causing the test to deadlock.
s.decline(driver, offer)
s.mut.Unlock()
return
}
configSummary := node.String()
taskID := &mesos.TaskID{Value: &configSummary}
executor := s.newExecutorInfo(node, s.executorUris)
task := &mesos.TaskInfo{
Data: serializedNodes,
Name: proto.String("etcd-server"),
TaskId: taskID,
SlaveId: offer.SlaveId,
Executor: executor,
Resources: []*mesos.Resource{
util.NewScalarResource("cpus", s.cpusPerTask),
util.NewScalarResource("mem", s.memPerTask),
util.NewScalarResource("disk", s.diskPerTask),
util.NewRangesResource("ports", []*mesos.Value_Range{
util.NewValueRange(uint64(rpcPort), uint64(httpPort)),
}),
},
Discovery: &mesos.DiscoveryInfo{
Visibility: mesos.DiscoveryInfo_EXTERNAL.Enum(),
Name: proto.String("etcd-server"),
Ports: &mesos.Ports{
Ports: []*mesos.Port{
&mesos.Port{
Number: proto.Uint32(uint32(rpcPort)),
Protocol: proto.String("tcp"),
},
// HACK: "client" is not a real SRV protocol. This is so
// that we can have etcd proxies use srv discovery on the
// above tcp name. Mesos-dns does not yet care about
// names for DiscoveryInfo. When it does, we should
// create a name for clients to use. We want to keep
// the rpcPort accessible at _etcd-server._tcp.<fwname>.mesos
&mesos.Port{
Number: proto.Uint32(uint32(clientPort)),
Protocol: proto.String("client"),
},
},
},
},
}
log.Infof(
"Prepared task: %s with offer %s for launch",
task.GetName(),
offer.Id.GetValue(),
)
log.Info("Launching etcd node.")
tasks := []*mesos.TaskInfo{task}
s.pending[node.Name] = struct{}{}
// This Unlock is not deferred because the test implementation of LaunchTasks
// calls this scheduler's StatusUpdate method, causing the test to deadlock.
s.mut.Unlock()
atomic.AddUint32(&s.Stats.LaunchedServers, 1)
driver.LaunchTasks(
[]*mesos.OfferID{offer.Id},
tasks,
&mesos.Filters{
RefuseSeconds: proto.Float64(1),
},
)
}