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


Golang proto.Int32函数代码示例

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


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

示例1: TestUpdate

func TestUpdate(t *testing.T) {
	neuralNetwork := CreateSimpleNetwork(t)
	inputs := mat64.NewDense(1, 2, []float64{0.05, 0.10})
	neuralNetwork.Forward(inputs)
	values := mat64.NewDense(1, 2, []float64{0.01, 0.99})
	neuralNetwork.Backward(values)
	learningConfiguration := neural.LearningConfiguration{
		Epochs:    proto.Int32(1),
		Rate:      proto.Float64(0.5),
		Decay:     proto.Float64(0),
		BatchSize: proto.Int32(1),
	}
	neuralNetwork.Update(learningConfiguration)
	expected_weights_0 := mat64.NewDense(
		3, 2, []float64{0.149780716, 0.24975114, 0.19956143, 0.29950229, 0.35,
			0.35})
	if !mat64.EqualApprox(
		neuralNetwork.Layers[0].Weight, expected_weights_0, 0.0001) {
		t.Errorf("weights 0 unexpected:\n%v",
			mat64.Formatted(neuralNetwork.Layers[0].Weight))
	}
	expected_weights_1 := mat64.NewDense(
		3, 2, []float64{0.35891648, 0.51130127, 0.408666186, 0.561370121, 0.6,
			0.6})
	if !mat64.EqualApprox(
		neuralNetwork.Layers[1].Weight, expected_weights_1, 0.0001) {
		t.Errorf("weights 1 unexpected:\n%v",
			mat64.Formatted(neuralNetwork.Layers[1].Weight))
	}
}
开发者ID:evilrobot69,项目名称:NeuralGo,代码行数:30,代码来源:network_test.go

示例2: ViewportCreate

//容器创建
func (vt *PBViewportCodec) ViewportCreate(id int32, container Entityer) interface{} {
	msg := &s2c.CreateView{}
	msg.Entity = proto.String(container.ObjTypeName())
	msg.ViewId = proto.Int32(id)
	msg.Capacity = proto.Int32(container.GetCapacity())
	return msg
}
开发者ID:mysll,项目名称:flynet,代码行数:8,代码来源:viewport.go

示例3: main

func main() {
	// marshal
	msg := new(demo.DemoMsg)
	msg.ClientId = proto.Int32(8)
	msg.ClientName = proto.String("foo")
	msg.Desc = proto.String("just a demo")
	item := new(demo.MsgItem)
	item.Id = proto.Int32(55)
	item.Name = proto.String("funky")
	t := demo.ItemType(demo.ItemType_TypeY)

	item.Type = &t
	msg.Items = append(msg.Items, item)
	fmt.Println(msg.String())
	data, err := proto.Marshal(msg)
	fmt.Println(err, data)

	// unmarshal
	var pb demo.DemoMsg
	err = proto.Unmarshal(data, &pb)
	if err != nil {
		panic(err)
	}

	fmt.Println(pb.String())
}
开发者ID:xinghuwang,项目名称:toolbox,代码行数:26,代码来源:main.go

示例4: PKDEL_Handler

// TODO: error code is not handled properly
func PKDEL_Handler(acMessagePkReq *AcPublicKeyMessageRequest) (acMsgResponse *AcPublicKeyMessageResponse, err error) {
	var responseType AcPublicKeyMessageResponseAcPKRespMsgType
	responseType = AcPublicKeyMessageResponse_PKR_DEL

	// request: type && nick && server                   -> delete the specific public key
	reqNick := acMessagePkReq.GetNick()
	reqServ := acMessagePkReq.GetServer()
	acutl.DebugLog.Printf("(CALL) PKDEL <- '%s' ! <host> / %s\n", reqNick, reqServ)

	if len(reqNick) > 0 && len(reqServ) > 0 { // IS A SPECIFIC NICK REQUESTED ?!?!
		//_, ok := Pk[reqNick]
		//Pk, ok := ackp.ACmap.GetPKMap(reqServ)
		ok := ackp.ACmap.DelPKMapEntry(reqServ, reqNick)
		if ok == true {
			//delete(Pk, reqNick)
			acMsgResponse = &AcPublicKeyMessageResponse{
				Type:      &responseType,
				Bada:      proto.Bool(true),
				ErrorCode: proto.Int32(0), // no such nickname
			}
			acutl.DebugLog.Printf("(RET) PKDEL -> (0) ! deleted key\n")
			return acMsgResponse, nil
		}
	}

	// XXX TODO: not sure If I should remove all keys or just return error
	retErr := &acutl.AcError{Value: -1, Msg: "PKDEL_Handler().reqServ|reqNick: 0 bytes", Err: nil}
	acMsgResponse = &AcPublicKeyMessageResponse{
		Type:      &responseType,
		Bada:      proto.Bool(false),
		ErrorCode: proto.Int32(-1), // no such nickname
	}
	acutl.DebugLog.Printf("(RET[!]) PKDEL -> (-1) ! missing argument\n")
	return acMsgResponse, retErr
}
开发者ID:gitter-badger,项目名称:ac,代码行数:36,代码来源:msg_pk.go

示例5: OnGetAchieves

func OnGetAchieves(s *Session, body []byte) *Packet {
	req := util.GetAchieves{}
	err := proto.Unmarshal(body, &req)
	if err != nil {
		panic(err)
	}
	res := util.Achieves{}
	dbfAchieves := []DbfAchieve{}
	db.Find(&dbfAchieves)
	for _, achieve := range dbfAchieves {
		achieveProgress := Achieve{}
		db.Where("achieve_id = ? and account_id = ?", achieve.ID, s.Account.ID).First(&achieveProgress)

		res.List = append(res.List, &util.Achieve{
			Id:              proto.Int32(achieve.ID),
			Progress:        proto.Int32(achieveProgress.Progress),
			AckProgress:     proto.Int32(achieveProgress.AckProgress),
			CompletionCount: proto.Int32(achieveProgress.CompletionCount),
			Active:          proto.Bool(achieveProgress.Active),
			DateGiven:       PegasusDate(achieveProgress.DateGiven),
			DateCompleted:   PegasusDate(achieveProgress.DateCompleted),
		})
	}
	return EncodePacket(util.Achieves_ID, &res)
}
开发者ID:Slko,项目名称:stove,代码行数:25,代码来源:account.go

示例6: CommonResultReturn

//通用的服务端返回给客户端的数据协议
func CommonResultReturn(conn interface{}, result string, resultId int32, num int32) {
	returnMsg := &protocol.WMessage{
		MsgType:   proto.String(result),
		MsgTypeId: proto.Int32(resultId),
		StataCode: proto.Int32(num),
	}

	buffer, err := proto.Marshal(returnMsg)
	if err != nil {
		Logger.Warn("protobuf marshal failed: ", err)
		fmt.Println("failed: ", err)
		//	Log.SetLogger("file", `{"filename": "savelog.log"}`)
		return
	}
	length := len(buffer)
	newbuffer := append(IntToBytes(length), buffer...)
	switch conn.(type) {
	case net.Conn:
		_, err := conn.(net.Conn).Write(newbuffer)
		CheckErr(err)
	case websocket.Conn:
		_, err := conn.(*websocket.Conn).Write(newbuffer)
		CheckErr(err)
	}
	return
}
开发者ID:happyEgg,项目名称:aTalk,代码行数:27,代码来源:protobuf_resultReturn.go

示例7: Log

func (l *evtLogger) Log(ctx context.Context, evt *crit_event.ChromeInfraEvent) {
	// Get this as soon as possible, so proto encoding time etc
	// doesn't bump the logged event time.
	clck := clock.Get(ctx)
	now := clck.Now().Unix()

	evt.EventSource = l.src
	// TODO: Consider making this a func parameter.
	evt.TimestampKind = crit_event.ChromeInfraEvent_POINT.Enum()

	if trace, ok := ctx.Value(TraceID).(string); ok {
		evt.TraceId = proto.String(trace)
	}

	// TODO:
	//	evt.SpanId = // ?
	//	evt.ParentId = // ?

	bytes, err := proto.Marshal(evt)
	if err != nil {
		logging.Errorf(ctx, "Error marshaling ChromeInfraEvent: %v", err.Error())
		return
	}

	l.evtCh <- &crit_event.LogRequestLite_LogEventLite{
		EventTimeMs:     proto.Int64(now),
		EventCode:       proto.Int32(0),
		EventFlowId:     proto.Int32(0),
		SourceExtension: bytes,
	}
}
开发者ID:nicko96,项目名称:Chrome-Infra,代码行数:31,代码来源:eventlogger.go

示例8: OnGetDeck

func OnGetDeck(s *Session, body []byte) ([]byte, error) {
	req := hsproto.PegasusUtil_GetDeck{}
	err := proto.Unmarshal(body, &req)
	if err != nil {
		return nil, err
	}

	id := req.GetDeck()
	var deck Deck
	db.First(&deck, id)

	// TODO: does this also need to allow brawl/arena decks? what about AI decks?
	if deck.DeckType != int(hsproto.PegasusShared_DeckType_PRECON_DECK) && deck.AccountID != s.Account.ID {
		return nil, fmt.Errorf("received OnGetDeck for non-precon deck not owned by account")
	}

	deckCards := []DeckCard{}
	db.Where("deck_id = ?", id).Find(&deckCards)

	res := hsproto.PegasusUtil_DeckContents{
		Deck: proto.Int64(id),
	}

	for i, card := range deckCards {
		cardData := &hsproto.PegasusShared_DeckCardData{
			Def:    MakeCardDef(card.CardID, card.Premium),
			Handle: proto.Int32(int32(i)),
			Qty:    proto.Int32(card.Num),
			Prev:   proto.Int32(int32(i) - 1),
		}
		res.Cards = append(res.Cards, cardData)
	}

	return EncodeUtilResponse(215, &res)
}
开发者ID:beheh,项目名称:stove,代码行数:35,代码来源:account.go

示例9: OnGetAchieves

func OnGetAchieves(s *Session, body []byte) ([]byte, error) {
	req := hsproto.PegasusUtil_GetAchieves{}
	err := proto.Unmarshal(body, &req)
	if err != nil {
		return nil, err
	}
	res := hsproto.PegasusUtil_Achieves{}
	dbfAchieves := []DbfAchieve{}
	db.Find(&dbfAchieves)
	for _, achieve := range dbfAchieves {
		achieveProgress := Achieve{}
		db.Where("achieve_id = ? and account_id = ?", achieve.ID, s.Account.ID).First(&achieveProgress)

		res.List = append(res.List, &hsproto.PegasusUtil_Achieve{
			Id:              proto.Int32(achieve.ID),
			Progress:        proto.Int32(achieveProgress.Progress),
			AckProgress:     proto.Int32(achieveProgress.AckProgress),
			CompletionCount: proto.Int32(achieveProgress.CompletionCount),
			Active:          proto.Bool(achieveProgress.Active),
			DateGiven:       PegasusDate(achieveProgress.DateGiven),
			DateCompleted:   PegasusDate(achieveProgress.DateCompleted),
		})
	}
	return EncodeUtilResponse(252, &res)
}
开发者ID:beheh,项目名称:stove,代码行数:25,代码来源:account.go

示例10: insert

// Insert can insert record into a btree
func (t *Btree) insert(record TreeLog) error {
	tnode, err := t.getTreeNode(t.GetRoot())
	if err != nil {
		if err.Error() != "no data" {
			return err
		}
		nnode := t.newTreeNode()
		nnode.NodeType = proto.Int32(isLeaf)
		_, err = nnode.insertRecord(record, t)
		if err == nil {
			t.Nodes[nnode.GetId()], err = proto.Marshal(nnode)
		}
		t.Root = proto.Int64(nnode.GetId())
		return err
	}
	clonednode, err := tnode.insertRecord(record, t)
	if err == nil && len(clonednode.GetKeys()) > int(t.GetNodeMax()) {
		nnode := t.newTreeNode()
		nnode.NodeType = proto.Int32(isNode)
		key, left, right := clonednode.split(t)
		nnode.insertOnce(key, left, right, t)
		t.Nodes[nnode.GetId()], err = proto.Marshal(nnode)
		t.Root = proto.Int64(nnode.GetId())
	} else {
		t.Root = proto.Int64(clonednode.GetId())
	}
	return err
}
开发者ID:datastream,项目名称:btree,代码行数:29,代码来源:insert.go

示例11: OnGetDeck

func OnGetDeck(s *Session, body []byte) *Packet {
	req := util.GetDeck{}
	err := proto.Unmarshal(body, &req)
	if err != nil {
		panic(err)
	}

	id := req.GetDeck()
	var deck Deck
	db.First(&deck, id)

	// TODO: does this also need to allow brawl/arena decks? what about AI decks?
	if deck.DeckType != int(shared.DeckType_PRECON_DECK) && deck.AccountID != s.Account.ID {
		log.Panicf("received OnGetDeck for non-precon deck not owned by account")
	}

	deckCards := []DeckCard{}
	db.Where("deck_id = ?", id).Find(&deckCards)

	res := util.DeckContents{
		Deck: proto.Int64(id),
	}

	for i, card := range deckCards {
		cardData := &shared.DeckCardData{
			Def:    MakeCardDef(card.CardID, card.Premium),
			Handle: proto.Int32(int32(i)),
			Qty:    proto.Int32(card.Num),
			Prev:   proto.Int32(int32(i) - 1),
		}
		res.Cards = append(res.Cards, cardData)
	}

	return EncodePacket(util.DeckContents_ID, &res)
}
开发者ID:Slko,项目名称:stove,代码行数:35,代码来源:account.go

示例12: NewStartRequest

func NewStartRequest(path string, dir string, args []string, allocated resource.ComputeResource, envs []string, host string, port int32) *cmd.ControlMessage {
	request := &cmd.ControlMessage{
		Type: cmd.ControlMessage_StartRequest.Enum(),
		StartRequest: &cmd.StartRequest{
			Path: proto.String(path),
			Args: args,
			Dir:  proto.String(dir),
			Resource: &cmd.ComputeResource{
				CpuCount: proto.Int32(int32(allocated.CPUCount)),
				CpuLevel: proto.Int32(int32(allocated.CPULevel)),
				Memory:   proto.Int32(int32(allocated.MemoryMB)),
			},
			Envs:     envs,
			Host:     proto.String(host),
			Port:     proto.Int32(port),
			HashCode: proto.Uint32(0),
		},
	}

	// generate a unique hash code for the request
	data, err := proto.Marshal(request)
	if err != nil {
		log.Fatalf("marshaling start request error: %v", err)
		return nil
	}
	request.StartRequest.HashCode = proto.Uint32(uint32(util.Hash(data)))

	return request
}
开发者ID:WUMUXIAN,项目名称:glow,代码行数:29,代码来源:command_execution.go

示例13: NewColumnPaginationFilter

// NewColumnPaginationFilter is TODO
func NewColumnPaginationFilter(limit, offset int32, columnOffset []byte) *ColumnPaginationFilter {
	return &ColumnPaginationFilter{
		Limit:        proto.Int32(limit),
		Offset:       proto.Int32(offset),
		ColumnOffset: columnOffset,
	}
}
开发者ID:jfrabaute,项目名称:gohbase,代码行数:8,代码来源:filter.go

示例14: processLogin

func processLogin(server *sev.Nexus, ipStr string,
	message *protocol.MobileSuiteModel) {
	loginDto := &protocol.LoginDTO{}
	proto.Unmarshal(message.Message, loginDto)

	userArr, err := server.DbConnector.QueryByUserName(
		*loginDto.UName, *loginDto.Pwd)
	if err != nil || userArr == nil || len(userArr) < 1 {
		sendBack(server, ipStr, nil,
			int32(protocol.MessageType_MSG_TYPE_LOGIN_RES))
		return
	}

	//loginResultDto := &protocol.LoginResultDTO{}
	//loginResultDto.UserId = loginDto.UserId
	//strName := strconv.FormatInt(*loginResultDto.UserId, 10)
	//loginResultDto.UName = &strName

	user := dao.User(userArr[0])

	// 登陆成功
	loginResultDto := &protocol.LoginResultDTO{}
	loginResultDto.UserId = proto.Int64(user.Id)
	loginResultDto.UName = &user.Name
	loginResultDto.Round = proto.Int32(int32(user.Round))
	loginResultDto.WinCount = proto.Int32(int32(user.WinCount))
	loginResultDto.Rank = proto.Int32(int32(user.Rank))

	byt, _ := proto.Marshal(loginResultDto)
	sendBack(server, ipStr, byt,
		int32(protocol.MessageType_MSG_TYPE_LOGIN_RES))
}
开发者ID:victoriest,项目名称:point_and_line,代码行数:32,代码来源:base_logic.go

示例15: MakeChest

func MakeChest() (chest shared.RewardChest) {
	// TODO take arguments to determine the contents
	// There are up to 5 bags each which can hold a booster, card, dust or gold

	chest.Bag1 = &shared.RewardBag{
		RewardBooster: &shared.ProfileNoticeRewardBooster{
			BoosterType:  proto.Int32(1),
			BoosterCount: proto.Int32(1),
		},
	}
	chest.Bag2 = &shared.RewardBag{
		RewardCard: &shared.ProfileNoticeRewardCard{
			Card:     MakeCardDef(2078, 1),
			Quantity: proto.Int32(1),
		},
	}
	chest.Bag3 = &shared.RewardBag{
		RewardDust: &shared.ProfileNoticeRewardDust{
			Amount: proto.Int32(69),
		},
	}
	chest.Bag4 = &shared.RewardBag{
		RewardGold: &shared.ProfileNoticeRewardGold{
			Amount: proto.Int32(42),
		},
	}
	return chest
}
开发者ID:synap5e,项目名称:stove,代码行数:28,代码来源:draft.go


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