当前位置: 首页>>代码示例>>Golang>>正文


Golang proto.Int32函数代码示例

本文整理汇总了Golang中goprotobuf/googlecode/com/hg/proto.Int32函数的典型用法代码示例。如果您正苦于以下问题:Golang Int32函数的具体用法?Golang Int32怎么用?Golang Int32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Int32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: updateCodecVersions

func (server *Server) updateCodecVersions() {
	codecusers := map[int32]int{}
	var winner int32
	var count int

	for _, client := range server.clients {
		for _, codec := range client.codecs {
			codecusers[codec] += 1
		}
	}

	for codec, users := range codecusers {
		if users > count {
			count = users
			winner = codec
		}
		if users == count && codec > winner {
			winner = codec
		}
	}

	var current int32
	if server.PreferAlphaCodec {
		current = server.AlphaCodec
	} else {
		current = server.BetaCodec
	}

	if winner == current {
		return
	}

	if winner == CeltCompatBitstream {
		server.PreferAlphaCodec = true
	} else {
		server.PreferAlphaCodec = !server.PreferAlphaCodec
	}

	if server.PreferAlphaCodec {
		server.AlphaCodec = winner
	} else {
		server.BetaCodec = winner
	}

	err := server.broadcastProtoMessage(MessageCodecVersion, &mumbleproto.CodecVersion{
		Alpha:       proto.Int32(server.AlphaCodec),
		Beta:        proto.Int32(server.BetaCodec),
		PreferAlpha: proto.Bool(server.PreferAlphaCodec),
	})
	if err != nil {
		log.Printf("Unable to broadcast.")
		return
	}

	log.Printf("CELT codec switch %#x %#x (PreferAlpha %v)", uint32(server.AlphaCodec), uint32(server.BetaCodec), server.PreferAlphaCodec)
	return
}
开发者ID:pcgod,项目名称:grumble,代码行数:57,代码来源:server.go

示例2: newTestMessage

func newTestMessage() *pb.MyMessage {
	msg := &pb.MyMessage{
		Count: proto.Int32(42),
		Name:  proto.String("Dave"),
		Quote: proto.String(`"I didn't want to go."`),
		Pet:   []string{"bunny", "kitty", "horsey"},
		Inner: &pb.InnerMessage{
			Host:      proto.String("footrest.syd"),
			Port:      proto.Int32(7001),
			Connected: proto.Bool(true),
		},
		Others: []*pb.OtherMessage{
			&pb.OtherMessage{
				Key:   proto.Int64(0xdeadbeef),
				Value: []byte{1, 65, 7, 12},
			},
			&pb.OtherMessage{
				Weight: proto.Float32(6.022),
				Inner: &pb.InnerMessage{
					Host: proto.String("lesha.mtv"),
					Port: proto.Int32(8002),
				},
			},
		},
		Bikeshed: pb.NewMyMessage_Color(pb.MyMessage_BLUE),
		Somegroup: &pb.MyMessage_SomeGroup{
			GroupField: proto.Int32(8),
		},
		// One normally wouldn't do this.
		// This is an undeclared tag 13, as a varint (wire type 0) with value 4.
		XXX_unrecognized: []byte{13<<3 | 0, 4},
	}
	ext := &pb.Ext{
		Data: proto.String("Big gobs for big rats"),
	}
	if err := proto.SetExtension(msg, pb.E_Ext_More, ext); err != nil {
		panic(err)
	}

	// Add an unknown extension. We marshal a pb.Ext, and fake the ID.
	b, err := proto.Marshal(&pb.Ext{Data: proto.String("3G skiing")})
	if err != nil {
		panic(err)
	}
	b = append(proto.EncodeVarint(104<<3|proto.WireBytes), b...)
	proto.SetRawExtension(msg, 104, b)

	// Extensions can be plain fields, too, so let's test that.
	b = append(proto.EncodeVarint(105<<3|proto.WireVarint), 19)
	proto.SetRawExtension(msg, 105, b)

	return msg
}
开发者ID:ashokgelal,项目名称:gorilla,代码行数:53,代码来源:text_test.go

示例3: toProto

// toProto converts the query to a protocol buffer.
func (q *Query) toProto(dst *pb.Query, appID string, zlp zeroLimitPolicy) error {
	if q.kind == "" {
		return errors.New("datastore: empty query kind")
	}
	dst.Reset()
	dst.App = proto.String(appID)
	dst.Kind = proto.String(q.kind)
	if q.ancestor != nil {
		dst.Ancestor = keyToProto(appID, q.ancestor)
	}
	if q.keysOnly {
		dst.KeysOnly = proto.Bool(true)
		dst.RequirePerfectPlan = proto.Bool(true)
	}
	for _, qf := range q.filter {
		if qf.FieldName == "" {
			return errors.New("datastore: empty query filter field name")
		}
		p, errStr := valueToProto(appID, qf.FieldName, reflect.ValueOf(qf.Value), false)
		if errStr != "" {
			return errors.New("datastore: bad query filter value type: " + errStr)
		}
		xf := &pb.Query_Filter{
			Op:       operatorToProto[qf.Op],
			Property: []*pb.Property{p},
		}
		if xf.Op == nil {
			return errors.New("datastore: unknown query filter operator")
		}
		dst.Filter = append(dst.Filter, xf)
	}
	for _, qo := range q.order {
		if qo.FieldName == "" {
			return errors.New("datastore: empty query order field name")
		}
		xo := &pb.Query_Order{
			Property:  proto.String(qo.FieldName),
			Direction: sortDirectionToProto[qo.Direction],
		}
		if xo.Direction == nil {
			return errors.New("datastore: unknown query order direction")
		}
		dst.Order = append(dst.Order, xo)
	}
	if q.limit != 0 || zlp == zeroLimitMeansZero {
		dst.Limit = proto.Int32(q.limit)
	}
	if q.offset != 0 {
		dst.Offset = proto.Int32(q.offset)
	}
	return nil
}
开发者ID:ashokgelal,项目名称:gorilla,代码行数:53,代码来源:query.go

示例4: UpdatePlayerCoordinate

func (this *PushProtoHandler) UpdatePlayerCoordinate(x, y int) {
	fmt.Printf("Updating player coordinate\n")
	m := NewUpdatePlayerCoord()
	m.Coord = new(Coordinate)
	m.Coord.X = proto.Int32(int32(x))
	m.Coord.Y = proto.Int32(int32(y))
	data, err := proto.Marshal(m)
	if err != nil {
		fmt.Printf("E: %s", err)
		return
	}
	this.Proxy.SendMsg(data, PORT_PUSH, Server_UPDATELOCATION, false)
}
开发者ID:gr0gmint,项目名称:gocon,代码行数:13,代码来源:protohandlers.go

示例5: Run

// Run starts a query for log records, which contain request and application
// level log information.
func (params *Query) Run(c appengine.Context) *Result {
	req := &log_proto.LogReadRequest{}
	appId := c.FullyQualifiedAppID()
	req.AppId = &appId
	if params.StartTime != 0 {
		req.StartTime = &params.StartTime
	}
	if params.EndTime != 0 {
		req.EndTime = &params.EndTime
	}
	if params.Incomplete {
		req.IncludeIncomplete = &params.Incomplete
	}
	if params.AppLogs {
		req.IncludeAppLogs = &params.AppLogs
	}
	if params.ApplyMinLevel {
		req.MinimumLogLevel = proto.Int32(int32(params.MinLevel))
	}
	if params.Versions == nil {
		// If no versions were specified, default to the major version
		// used by this app.
		versionID := appengine.VersionID(c)
		if i := strings.Index(versionID, "."); i >= 0 {
			versionID = versionID[:i]
		}
		req.VersionId = []string{versionID}
	} else {
		req.VersionId = params.Versions
	}

	return &Result{context: c, request: req}
}
开发者ID:ashokgelal,项目名称:gorilla,代码行数:35,代码来源:log.go

示例6: TestPBS

func TestPBS(t *testing.T) {

	memStore := NewMemoryStore()
	stores := [1]DataStore{memStore}
	ds := NewPBSDataStore(&stores)

	test := &Test{
		Label: proto.String("hello"),
		Type:  proto.Int32(17),
		Optionalgroup: &Test_OptionalGroup{
			RequiredField: proto.String("good bye"),
		},
	}

	key, err := ds.Put(test)
	if err != nil {
		t.Fatalf("Put failed: %q", err.String())
	}
	t.Logf("Key: %q", key)

	test2 := NewTest()
	err2 := ds.Get(key, test2)

	if err2 != nil {
		t.Fatalf("Get failed: %q", err.String())
	}
	t.Logf("Value: %q", *test2.Label)
}
开发者ID:newblue,项目名称:pbs.go,代码行数:28,代码来源:pbs_test.go

示例7: Walk

// Walk reads up to lim entries matching glob, in revision rev, into an array.
// Entries are read in lexicographical order, starting at position off.
// A negative lim means to read until the end.
// Conn.Walk will be removed in a future release. Use Walk instead.
func (c *Conn) Walk(glob string, rev int64, off, lim int) (info []Event, err os.Error) {
	for lim != 0 {
		var t txn
		t.req.Verb = newRequest_Verb(request_WALK)
		t.req.Rev = &rev
		t.req.Path = &glob
		t.req.Offset = proto.Int32(int32(off))
		err = c.call(&t)
		if err, ok := err.(*Error); ok && err.Err == ErrRange {
			return info, nil
		}
		if err != nil {
			return nil, err
		}
		info = append(info, Event{
			*t.resp.Rev,
			*t.resp.Path,
			t.resp.Value,
			*t.resp.Flags,
		})
		off++
		lim--
	}
	return
}
开发者ID:mloughran,项目名称:doozer,代码行数:29,代码来源:conn.go

示例8: callNext

// callNext issues a datastore_v3/Next RPC to advance a cursor, such as that
// returned by a query with more results.
func callNext(c appengine.Context, res *pb.QueryResult, offset, limit int32, zlp zeroLimitPolicy) error {
	if res.Cursor == nil {
		return errors.New("datastore: internal error: server did not return a cursor")
	}
	// TODO: should I eventually call datastore_v3/DeleteCursor on the cursor?
	req := &pb.NextRequest{
		Cursor: res.Cursor,
		Offset: proto.Int32(offset),
	}
	if limit != 0 || zlp == zeroLimitMeansZero {
		req.Count = proto.Int32(limit)
	}
	if res.CompiledCursor != nil {
		req.Compile = proto.Bool(true)
	}
	res.Reset()
	return c.Call("datastore_v3", "Next", req, res, nil)
}
开发者ID:ashokgelal,项目名称:gorilla,代码行数:20,代码来源:query.go

示例9: respond

func (c *conn) respond(t *T, flag int32, cc chan bool, r *R) {
	r.Tag = t.Tag
	r.Flags = pb.Int32(flag)
	tag := pb.GetInt32(t.Tag)

	if flag&Done != 0 {
		c.closeTxn(tag)
	}

	if c.poisoned {
		select {
		case cc <- true:
		default:
		}
		return
	}

	buf, err := pb.Marshal(r)
	c.wl.Lock()
	defer c.wl.Unlock()
	if err != nil {
		c.poisoned = true
		select {
		case cc <- true:
		default:
		}
		log.Println(err)
		return
	}

	err = binary.Write(c.c, binary.BigEndian, int32(len(buf)))
	if err != nil {
		c.poisoned = true
		select {
		case cc <- true:
		default:
		}
		log.Println(err)
		return
	}

	for len(buf) > 0 {
		n, err := c.c.Write(buf)
		if err != nil {
			c.poisoned = true
			select {
			case cc <- true:
			default:
			}
			log.Println(err)
			return
		}

		buf = buf[n:]
	}
}
开发者ID:kr,项目名称:doozerd,代码行数:56,代码来源:server.go

示例10: TestSetNilFields

func TestSetNilFields(t *testing.T) {
	c := &conn{
		c:   &bytes.Buffer{},
		s:   &Server{},
		cal: true,
		tx:  make(map[int32]txn),
	}
	c.set(&T{Tag: proto.Int32(1)}, newTxn())
	assertResponse(t, missingArg, c)
}
开发者ID:kr,项目名称:doozer,代码行数:10,代码来源:server_test.go

示例11: main

func main() {
	m1 := &test.Member{
		Name: proto.String("Linus"),
		Age:  proto.Int32(99),
	}
	m1.Skills = []test.Skill{test.Skill_ASM, test.Skill_C}
	m1_data, err := proto.Marshal(m1)
	if err != nil {
		log.Fatal("marshaling error: ", err)
		os.Exit(1)
	}
	fmt.Println("m1:          ", m1)
	fmt.Println("m1.Skills:   ", m1.Skills)
	fmt.Println("actual data: ", m1_data)
	println("=== unmarshalling m1 into m2 ===")

	m2 := &test.Member{}
	proto.Unmarshal(m1_data, m2)
	fmt.Println("m2:          ", m2)

	port := 9090
	fmt.Println("=== END EXAMPLES / SERVER STARTING at %d ===", port)
	service := fmt.Sprintf(":%d", port)
	tcpAddr, err := net.ResolveTCPAddr("ip4", service)
	checkError(err)

	listener, err := net.ListenTCP("tcp", tcpAddr)
	checkError(err)

	for {
		conn, err := listener.Accept()
		checkError(err)

		input := make([]byte, 1024)
		n, err := conn.Read(input)
		input = input[:n]
		fmt.Println("input: ", input)
		club := &test.Club{}
		err = proto.Unmarshal(input, club)
		checkError(err)

		sum := int32(0)
		fmt.Println("len: ", len(club.Member))
		for _, m := range club.Member {
			sum += *m.Age
		}
		avg := float64(sum) / float64(len(club.Member))
		fmt.Printf("avg age: %f   (sum: %d)\n", avg, sum)
		reply := &test.Reply{Average: proto.Float64(avg)}
		out_data, err := proto.Marshal(reply)
		conn.Write(out_data) // don't care about return value
		conn.Close()         // we're finished with this client
	}

}
开发者ID:haraldschilly,项目名称:gtug-protobuf-talk,代码行数:55,代码来源:main.go

示例12: makeRemoveEntity

func makeRemoveEntity(id int32, name string) (msg *protocol.Message) {
	removeEntity := &protocol.RemoveEntity{
		Id:   proto.Int32(id),
		Name: proto.String(name),
	}

	return &protocol.Message{
		RemoveEntity: removeEntity,
		Type:         protocol.NewMessage_Type(protocol.Message_REMOVEENTITY),
	}
}
开发者ID:archwyrm,项目名称:ghack,代码行数:11,代码来源:messages.go

示例13: makeAddEntity

func makeAddEntity(id int32, name string) (msg *protocol.Message) {
	addEntity := &protocol.AddEntity{
		Id:   proto.Int32(id),
		Name: proto.String(name),
	}

	return &protocol.Message{
		AddEntity: addEntity,
		Type:      protocol.NewMessage_Type(protocol.Message_ADDENTITY),
	}
}
开发者ID:archwyrm,项目名称:ghack,代码行数:11,代码来源:messages.go

示例14: makeUpdateState

func makeUpdateState(id int32, stateId string, value *protocol.StateValue) (msg *protocol.Message) {
	updateState := &protocol.UpdateState{
		Id:      proto.Int32(id),
		StateId: proto.String(stateId),
		Value:   value,
	}

	return &protocol.Message{
		UpdateState: updateState,
		Type:        protocol.NewMessage_Type(protocol.Message_UPDATESTATE),
	}
}
开发者ID:archwyrm,项目名称:ghack,代码行数:12,代码来源:messages.go

示例15: readEnum

func (p *parser) readEnum(e *EnumDescriptorProto) *parseError {
	if err := p.readToken("enum"); err != nil {
		return err
	}

	tok := p.next()
	if tok.err != nil {
		return tok.err
	}
	// TODO: check that the name is acceptable.
	e.Name = proto.String(tok.value)

	if err := p.readToken("{"); err != nil {
		return err
	}

	// Parse enum values
	for !p.done {
		tok := p.next()
		if tok.err != nil {
			return tok.err
		}
		if tok.value == "}" {
			// end of enum
			return nil
		}
		// TODO: verify tok.value is a valid enum value name.
		ev := new(EnumValueDescriptorProto)
		e.Value = append(e.Value, ev)
		ev.Name = proto.String(tok.value)

		if err := p.readToken("="); err != nil {
			return err
		}

		tok = p.next()
		if tok.err != nil {
			return tok.err
		}
		// TODO: check that tok.value is a valid enum value number.
		num, err := atoi32(tok.value)
		if err != nil {
			return p.error("bad enum number %q: %v", tok.value, err)
		}
		ev.Number = proto.Int32(num)

		if err := p.readToken(";"); err != nil {
			return err
		}
	}

	return p.error("unexpected end while parsing enum")
}
开发者ID:welterde,项目名称:gotoc,代码行数:53,代码来源:parser.go


注:本文中的goprotobuf/googlecode/com/hg/proto.Int32函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。