當前位置: 首頁>>代碼示例>>Golang>>正文


Golang proto.Uint32函數代碼示例

本文整理匯總了Golang中goprotobuf/googlecode/com/hg/proto.Uint32函數的典型用法代碼示例。如果您正苦於以下問題:Golang Uint32函數的具體用法?Golang Uint32怎麽用?Golang Uint32使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Uint32函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: set

// set sets the given items using the given conflict resolution policy.
// The returned slice will have the same length as the input slice.
// If value is not nil, each element should correspond to an item.
func set(c appengine.Context, item []*Item, value [][]byte, policy int32) []os.Error {
	req := &pb.MemcacheSetRequest{
		Item: make([]*pb.MemcacheSetRequest_Item, len(item)),
	}
	for i, t := range item {
		p := &pb.MemcacheSetRequest_Item{
			Key: []byte(t.Key),
		}
		if value == nil {
			p.Value = t.Value
		} else {
			p.Value = value[i]
		}
		if t.Flags != 0 {
			p.Flags = proto.Uint32(t.Flags)
		}
		if t.Expiration != 0 {
			// In the .proto file, MemcacheSetRequest_Item uses a fixed32 (i.e. unsigned)
			// for expiration time, while MemcacheGetRequest_Item uses int32 (i.e. signed).
			// Throughout this .go file, we use int32.
			p.ExpirationTime = proto.Uint32(uint32(t.Expiration))
		}
		if t.casID != 0 {
			p.CasId = proto.Uint64(t.casID)
			p.ForCas = proto.Bool(true)
		}
		p.SetPolicy = pb.NewMemcacheSetRequest_SetPolicy(policy)
		req.Item[i] = p
	}
	res := &pb.MemcacheSetResponse{}
	e := make([]os.Error, len(item))
	if err := c.Call("memcache", "Set", req, res); err != nil {
		for i := range e {
			e[i] = err
		}
		return e
	}
	if len(e) != len(res.SetStatus) {
		for i := range e {
			e[i] = ErrServerError
		}
		return e
	}
	for i := range e {
		switch res.SetStatus[i] {
		case pb.MemcacheSetResponse_STORED:
			e[i] = nil
		case pb.MemcacheSetResponse_NOT_STORED:
			e[i] = ErrNotStored
		case pb.MemcacheSetResponse_EXISTS:
			e[i] = ErrCASConflict
		default:
			e[i] = ErrServerError
		}
	}
	return e
}
開發者ID:sarnowski,項目名稱:google-go-lang-idea-plugin,代碼行數:60,代碼來源:memcache.go

示例2: interface2value

func interface2value(data interface{}) *TransactionValue {
	switch f := data.(type) {

	case string:
		return &TransactionValue{
			Type:        proto.Uint32(val_string),
			StringValue: proto.String(f),
		}
	}

	return &TransactionValue{
		Type: proto.Uint32(val_null),
	}
}
開發者ID:appaquet,項目名稱:gostore,代碼行數:14,代碼來源:transaction.go

示例3: sendPermissionDenied

// Send permission denied by who, what, where
func (c *Client) sendPermissionDenied(who *Client, where *Channel, what Permission) {
	d, err := proto.Marshal(&mumbleproto.PermissionDenied{
		Permission: proto.Uint32(uint32(what)),
		ChannelId:  proto.Uint32(uint32(where.Id)),
		Session:    proto.Uint32(who.Session),
		Type:       mumbleproto.NewPermissionDenied_DenyType(mumbleproto.PermissionDenied_Permission),
	})
	if err != nil {
		c.Panic(err.String())
	}
	c.msgchan <- &Message{
		buf:  d,
		kind: MessagePermissionDenied,
	}
}
開發者ID:pcgod,項目名稱:grumble,代碼行數:16,代碼來源:client.go

示例4: executeTransaction

//
// Get
//
func (op *TransactionOperation_Get) executeTransaction(t *Transaction, b *TransactionBlock, vs *viewState) (ret *TransactionReturn) {
	// TODO: Walk!

	var value *TransactionValue

	if op.Source.Variable != nil {
		sourceVar := b.getRealVar(op.Source.Variable.Variable)
		value = sourceVar.Value

	} else if op.Source.Object != nil {
		// make sure we don't use variables anymore
		for _, ac := range op.Accessors {
			ac.MakeAbsoluteValue(b)
		}

		obj, osErr := vs.getObject(op.Source.Object.Container.Value().(string), op.Source.Object.Key.Value().(string), true)
		if osErr != nil {
			return &TransactionReturn{
				Error: &TransactionError{
					Id:      proto.Uint32(0), // TODO: ERRNO
					Message: proto.String(osErr.String()),
				},
			}
		}
		value = interface2value(obj.data)
	}

	destVar := b.getRealVar(op.Destination)
	destVar.Value = value

	return
}
開發者ID:appaquet,項目名稱:gostore,代碼行數:35,代碼來源:operations.go

示例5: Return

func (b *TransactionBlock) Return(data ...interface{}) {
	op := &TransactionOperation{
		Type:   proto.Uint32(op_return),
		Return: &TransactionOperation_Return{},
	}
	op.Return.Returns = make([]*TransactionObject, len(data))

	for i, obj := range data {
		if vr, ok := obj.(*TransactionVariable); ok {
			op.Return.Returns[i] = &TransactionObject{
				Variable: vr,
			}
		} else {
			val := interface2value(obj)
			if val == nil {
				panic("Unknown return object")
			}

			op.Return.Returns[i] = &TransactionObject{
				Value: val,
			}
		}
	}

	b.addOperation(op)
}
開發者ID:appaquet,項目名稱:gostore,代碼行數:26,代碼來源:transaction.go

示例6: handleTextMessage

// Broadcast text messages
func (server *Server) handleTextMessage(client *Client, msg *Message) {
	txtmsg := &mumbleproto.TextMessage{}
	err := proto.Unmarshal(msg.buf, txtmsg)
	if err != nil {
		client.Panic(err.String())
		return
	}

	// fixme(mkrautz): Check text message length.
	// fixme(mkrautz): Sanitize text as well.

	clients := make(map[uint32]*Client)

	// Tree
	for _, chanid := range txtmsg.TreeId {
		if channel, ok := server.Channels[int(chanid)]; ok {
			if !server.HasPermission(client, channel, TextMessagePermission) {
				client.sendPermissionDenied(client, channel, TextMessagePermission)
			}
			for _, target := range channel.clients {
				clients[target.Session] = target
			}
		}
	}

	// Direct-to-channel
	for _, chanid := range txtmsg.ChannelId {
		if channel, ok := server.Channels[int(chanid)]; ok {
			if !server.HasPermission(client, channel, TextMessagePermission) {
				client.sendPermissionDenied(client, channel, TextMessagePermission)
				return
			}
			for _, target := range channel.clients {
				clients[target.Session] = target
			}
		}
	}

	// Direct-to-clients
	for _, session := range txtmsg.Session {
		if target, ok := server.clients[session]; ok {
			if !server.HasPermission(client, target.Channel, TextMessagePermission) {
				client.sendPermissionDenied(client, target.Channel, TextMessagePermission)
				return
			}
			clients[session] = target
		}
	}

	// Remove ourselves
	clients[client.Session] = nil, false

	for _, target := range clients {
		target.sendProtoMessage(MessageTextMessage, &mumbleproto.TextMessage{
			Actor:   proto.Uint32(client.Session),
			Message: txtmsg.Message,
		})
	}
}
開發者ID:pcgod,項目名稱:grumble,代碼行數:60,代碼來源:message.go

示例7: makeConnect

func makeConnect() (msg *protocol.Message) {
	connect := &protocol.Connect{Version: proto.Uint32(ProtocolVersion)}

	return &protocol.Message{
		Connect: connect,
		Type:    protocol.NewMessage_Type(protocol.Message_CONNECT),
	}
}
開發者ID:archwyrm,項目名稱:ghack,代碼行數:8,代碼來源:messages.go

示例8: NewVar

func (b *TransactionBlock) NewVar() *TransactionVariable {
	v := new(TransactionVariable)

	// TODO: we should only add variables that have values
	v.Block = b.Id
	v.Id = proto.Uint32(uint32(len(b.Variables)))
	b.Variables = append(b.Variables, v)
	return v
}
開發者ID:appaquet,項目名稱:gostore,代碼行數:9,代碼來源:transaction.go

示例9: handlePingMessage

func (server *Server) handlePingMessage(client *Client, msg *Message) {
	ping := &mumbleproto.Ping{}
	err := proto.Unmarshal(msg.buf, ping)
	if err != nil {
		client.Panic(err.String())
		return
	}

	// Phony response for ping messages. We don't keep stats
	// for this yet.
	client.sendProtoMessage(MessagePing, &mumbleproto.Ping{
		Timestamp: ping.Timestamp,
		Good:      proto.Uint32(uint32(client.crypt.Good)),
		Late:      proto.Uint32(uint32(client.crypt.Late)),
		Lost:      proto.Uint32(uint32(client.crypt.Lost)),
		Resync:    proto.Uint32(uint32(client.crypt.Resync)),
	})
}
開發者ID:pcgod,項目名稱:grumble,代碼行數:18,代碼來源:message.go

示例10: sendClientPermissions

// Send a client its permissions for channel.
func (server *Server) sendClientPermissions(client *Client, channel *Channel) {
	// No caching for SuperUser
	if client.IsSuperUser() {
		return
	}

	// Update cache
	server.HasPermission(client, channel, EnterPermission)

	perm := server.aclcache.GetPermission(client, channel)
	log.Printf("Permissions = 0x%x", perm)

	// fixme(mkrautz): Cache which permissions we've already sent.
	client.sendProtoMessage(MessagePermissionQuery, &mumbleproto.PermissionQuery{
		ChannelId:   proto.Uint32(uint32(channel.Id)),
		Permissions: proto.Uint32(uint32(perm)),
	})
}
開發者ID:pcgod,項目名稱:grumble,代碼行數:19,代碼來源:server.go

示例11: sendChannelTree

func (client *Client) sendChannelTree(channel *Channel) {
	chanstate := &mumbleproto.ChannelState{
		ChannelId: proto.Uint32(uint32(channel.Id)),
		Name:      proto.String(channel.Name),
	}
	if channel.parent != nil {
		chanstate.Parent = proto.Uint32(uint32(channel.parent.Id))
	}

	if channel.HasDescription() {
		if client.Version >= 0x10202 {
			chanstate.DescriptionHash = channel.DescriptionBlobHashBytes()
		} else {
			buf, err := globalBlobstore.Get(channel.DescriptionBlob)
			if err != nil {
				panic("Blobstore error.")
			}
			chanstate.Description = proto.String(string(buf))
		}
	}

	if channel.Temporary {
		chanstate.Temporary = proto.Bool(true)
	}

	chanstate.Position = proto.Int32(int32(channel.Position))

	links := []uint32{}
	for cid, _ := range channel.Links {
		links = append(links, uint32(cid))
	}
	chanstate.Links = links

	err := client.sendProtoMessage(MessageChannelState, chanstate)
	if err != nil {
		client.Panic(err.String())
	}

	for _, subchannel := range channel.children {
		client.sendChannelTree(subchannel)
	}
}
開發者ID:pcgod,項目名稱:grumble,代碼行數:42,代碼來源:client.go

示例12: makeLogin

func makeLogin(name string, authToken string, permissions uint32) (msg *protocol.Message) {
	login := &protocol.Login{
		Name:        proto.String(name),
		Authtoken:   proto.String(authToken),
		Permissions: proto.Uint32(permissions),
	}

	return &protocol.Message{
		Login: login,
		Type:  protocol.NewMessage_Type(protocol.Message_LOGIN),
	}
}
開發者ID:archwyrm,項目名稱:ghack,代碼行數:12,代碼來源:messages.go

示例13: handleUserRemoveMessage

// Handle a user remove packet. This can either be a client disconnecting, or a
// user kicking or kick-banning another player.
func (server *Server) handleUserRemoveMessage(client *Client, msg *Message) {
	userremove := &mumbleproto.UserRemove{}
	err := proto.Unmarshal(msg.buf, userremove)
	if err != nil {
		client.Panic(err.String())
	}

	// Get the client to be removed.
	removeClient, ok := server.clients[*userremove.Session]
	if !ok {
		client.Panic("Invalid session in UserRemove message")
		return
	}

	ban := false
	if userremove.Ban != nil {
		ban = *userremove.Ban
	}

	// Check client's permissions
	perm := Permission(KickPermission)
	if ban {
		perm = Permission(BanPermission)
	}

	if removeClient.IsSuperUser() || !server.HasPermission(client, server.root, perm) {
		client.sendPermissionDenied(client, server.root, perm)
		return
	}

	if ban {
		// fixme(mkrautz): Implement banning.
		log.Printf("handleUserRemove: Banning is not yet implemented.")
	}

	userremove.Actor = proto.Uint32(uint32(client.Session))
	if err = server.broadcastProtoMessage(MessageUserRemove, userremove); err != nil {
		log.Panic("Unable to broadcast UserRemove message")
		return
	}

	removeClient.ForceDisconnect()
}
開發者ID:pcgod,項目名稱:grumble,代碼行數:45,代碼來源:message.go

示例14: sendPermissionDeniedTypeUser

// Send permission denied by type (and user)
func (c *Client) sendPermissionDeniedTypeUser(kind string, user *Client) {
	val, ok := mumbleproto.PermissionDenied_DenyType_value[kind]
	if ok {
		pd := &mumbleproto.PermissionDenied{}
		pd.Type = mumbleproto.NewPermissionDenied_DenyType(val)
		if user != nil {
			pd.Session = proto.Uint32(uint32(user.Session))
		}
		d, err := proto.Marshal(pd)
		if err != nil {
			c.Panic(err.String())
			return
		}
		c.msgchan <- &Message{
			buf:  d,
			kind: MessagePermissionDenied,
		}
	} else {
		log.Panic("Unknown permission denied type.")
	}
}
開發者ID:pcgod,項目名稱:grumble,代碼行數:22,代碼來源:client.go

示例15: init

//type TransactionBlock struct {
//	Id			*uint32			"PB(varint,1,req,name=id)"
//	Parent			*TransactionBlock	"PB(bytes,2,opt,name=parent)"
//	Operations		[]*TransactionOperation	"PB(bytes,5,rep,name=operations)"
//	VariableCount		*uint32			"PB(varint,6,opt,name=variable_count)"
//	Variables		[]*TransactionVariable	"PB(bytes,7,rep,name=variables)"
//	XXX_unrecognized	[]byte
//}
func (b *TransactionBlock) init(t *Transaction, ti *transactionInfo) (err os.Error) {

	// initialize variables
	if b.VariableCount != nil && len(b.Variables) != int(*b.VariableCount) {
		newVars := make([]*TransactionVariable, int(*b.VariableCount))
		for _, vr := range b.Variables {
			newVars[*vr.Id] = vr
		}

		for i := uint32(0); i < *b.VariableCount; i++ {
			if newVars[i] == nil {
				newVars[i] = &TransactionVariable{
					Block: b.Id,
					Id:    proto.Uint32(i),
				}
			}
		}
	}

	// initialize operations
	for _, op := range b.Operations {
		switch *op.Type {

		case op_return:
			err = op.Return.init(t, ti)

		case op_set:
			err = op.Set.init(t, ti)

		case op_get:
			err = op.Get.init(t, ti)
		}

		if err != nil {
			return
		}
	}

	return
}
開發者ID:appaquet,項目名稱:gostore,代碼行數:48,代碼來源:transaction.go


注:本文中的goprotobuf/googlecode/com/hg/proto.Uint32函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。