本文整理汇总了Golang中github.com/golang/protobuf/proto.Int64函数的典型用法代码示例。如果您正苦于以下问题:Golang Int64函数的具体用法?Golang Int64怎么用?Golang Int64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Int64函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: makeRequest
func makeRequest(fix fixture, wants, has float64) (*pb.GetCapacityResponse, error) {
req := &pb.GetCapacityRequest{
ClientId: proto.String("client"),
Resource: []*pb.ResourceRequest{
{
ResourceId: proto.String("resource"),
Priority: proto.Int64(1),
Has: &pb.Lease{
ExpiryTime: proto.Int64(0),
RefreshInterval: proto.Int64(0),
Capacity: proto.Float64(0),
},
Wants: proto.Float64(wants),
},
},
}
if has > 0 {
req.Resource[0].Has = &pb.Lease{
ExpiryTime: proto.Int64(time.Now().Add(1 * time.Minute).Unix()),
RefreshInterval: proto.Int64(5),
Capacity: proto.Float64(has),
}
}
return fix.client.GetCapacity(context.Background(), req)
}
开发者ID:youtube,项目名称:doorman,代码行数:27,代码来源:server_test.go
示例2: executeFunc
// TODO: Use gauge-go result object rather than ProtoExecutionResult
func executeFunc(fn reflect.Value, args ...interface{}) (res *m.ProtoExecutionResult) {
rargs := make([]reflect.Value, len(args))
for i, a := range args {
rargs[i] = reflect.ValueOf(a)
}
res = &m.ProtoExecutionResult{}
T = &testingT{}
start := time.Now()
defer func() {
if r := recover(); r != nil {
res.ScreenShot = getScreenshot()
res.Failed = proto.Bool(true)
res.ExecutionTime = proto.Int64(time.Since(start).Nanoseconds())
res.StackTrace = proto.String(strings.SplitN(string(debug.Stack()), "\n", 9)[8])
res.ErrorMessage = proto.String(fmt.Sprintf("%s", r))
}
T = &testingT{}
}()
fn.Call(rargs)
res.Failed = proto.Bool(false)
if len(T.errors) != 0 {
res.ScreenShot = getScreenshot()
res.Failed = proto.Bool(true)
res.StackTrace = proto.String(T.getStacktraces())
res.ErrorMessage = proto.String(T.getErrors())
}
res.ExecutionTime = proto.Int64(time.Since(start).Nanoseconds())
return res
}
开发者ID:manuviswam,项目名称:gauge-go,代码行数:30,代码来源:funcExecutor.go
示例3: Leave
func (u *User) Leave() {
notifyMsg := new(gs_protocol.NotifyQuitMsg)
if DEBUG {
gsutil.Log("Leave user id : ", gsutil.Itoa64(u.userID))
}
notifyMsg.UserID = proto.Int64(u.userID)
if u.room != nil {
if DEBUG {
gsutil.Log("Leave room id : ", gsutil.Itoa64(u.room.roomID))
}
notifyMsg.RoomID = proto.Int64(u.room.roomID)
msg, err := proto.Marshal(notifyMsg)
gsutil.CheckError(err)
// race condition by broadcast goroutine and ClientSender goroutine
u.room.Leave(u.userID)
// notify all members in the room
u.SendToAll(NewMessage(u.userID, gs_protocol.Type_NotifyQuit, msg))
if DEBUG {
gsutil.Log("NotifyQuit message send")
}
}
if DEBUG {
gsutil.Log("Leave func end")
}
}
开发者ID:ohsaean,项目名称:gogpd,代码行数:30,代码来源:user.go
示例4: toAuthDBRevision
// toAuthDBRevision converts AuthReplicationState to AuthDBRevision proto.
func toAuthDBRevision(rs *model.AuthReplicationState) *AuthDBRevision {
return &AuthDBRevision{
PrimaryId: proto.String(rs.PrimaryID),
AuthDbRev: proto.Int64(rs.AuthDBRev),
ModifiedTs: proto.Int64(timeToTimestamp(rs.ModifiedTimestamp)),
}
}
开发者ID:shishkander,项目名称:luci-go,代码行数:8,代码来源:converter.go
示例5: TestProto3SetDefaults
func TestProto3SetDefaults(t *testing.T) {
in := &pb.Message{
Terrain: map[string]*pb.Nested{
"meadow": new(pb.Nested),
},
Proto2Field: new(tpb.SubDefaults),
Proto2Value: map[string]*tpb.SubDefaults{
"badlands": new(tpb.SubDefaults),
},
}
got := proto.Clone(in).(*pb.Message)
proto.SetDefaults(got)
// There are no defaults in proto3. Everything should be the zero value, but
// we need to remember to set defaults for nested proto2 messages.
want := &pb.Message{
Terrain: map[string]*pb.Nested{
"meadow": new(pb.Nested),
},
Proto2Field: &tpb.SubDefaults{N: proto.Int64(7)},
Proto2Value: map[string]*tpb.SubDefaults{
"badlands": {N: proto.Int64(7)},
},
}
if !proto.Equal(got, want) {
t.Errorf("with in = %v\nproto.SetDefaults(in) =>\ngot %v\nwant %v", in, got, want)
}
}
开发者ID:zhangcunli,项目名称:go-demo,代码行数:30,代码来源:proto3_test.go
示例6: ConsensusUpdate
// ConsensusUpdate implements paxos.Watcher interface.
func (this *Election) ConsensusUpdate(uid string, index int64, value []byte) {
round := this.ElectionRoundFromPaxosUID(uid)
if round <= this.CurrentRound() {
return
}
winner := string(value)
lock, errLock := this.ctlr.LockAll()
if errLock != nil {
return
}
defer lock.Unlock()
change := thispb.ElectionChange{}
change.ElectionRound = proto.Int64(round)
change.ElectionWinner = proto.String(winner)
if err := this.doUpdateElection(&change); err != nil {
this.Fatalf("could not update new election round status: %v", err)
}
if this.InCommittee() {
change := thispb.CommitteeChange{}
change.NewElectionRound = proto.Int64(round)
change.NewElectionWinner = proto.String(winner)
if err := this.doUpdateCommittee(&change); err != nil {
this.Fatalf("could not update committee with new election status: %v",
err)
}
}
}
开发者ID:bvk,项目名称:ascent,代码行数:31,代码来源:election.go
示例7: NewPost
// NewPost creates a message header for a post message.
func (this *Messenger) NewPost() *msgpb.Header {
header := &msgpb.Header{}
header.MessageId = proto.Int64(atomic.AddInt64(&this.lastMessageID, 1))
header.MessengerId = proto.String(this.uid)
header.CreateTimestampNsecs = proto.Int64(time.Now().UnixNano())
return header
}
开发者ID:bvk,项目名称:ascent,代码行数:8,代码来源:messenger.go
示例8: setExecutionResultForConcept
func (executor *specExecutor) setExecutionResultForConcept(protoConcept *gauge_messages.ProtoConcept) {
var conceptExecutionTime int64
for _, step := range protoConcept.GetSteps() {
if step.GetItemType() == gauge_messages.ProtoItem_Concept {
stepExecResult := step.GetConcept().GetConceptExecutionResult().GetExecutionResult()
conceptExecutionTime += stepExecResult.GetExecutionTime()
if step.GetConcept().GetConceptExecutionResult().GetExecutionResult().GetFailed() {
conceptExecutionResult := &gauge_messages.ProtoStepExecutionResult{ExecutionResult: step.GetConcept().GetConceptExecutionResult().GetExecutionResult(), Skipped: proto.Bool(false)}
conceptExecutionResult.ExecutionResult.ExecutionTime = proto.Int64(conceptExecutionTime)
protoConcept.ConceptExecutionResult = conceptExecutionResult
protoConcept.ConceptStep.StepExecutionResult = conceptExecutionResult
return
}
} else if step.GetItemType() == gauge_messages.ProtoItem_Step {
stepExecResult := step.GetStep().GetStepExecutionResult().GetExecutionResult()
conceptExecutionTime += stepExecResult.GetExecutionTime()
if stepExecResult.GetFailed() {
conceptExecutionResult := &gauge_messages.ProtoStepExecutionResult{ExecutionResult: stepExecResult, Skipped: proto.Bool(false)}
conceptExecutionResult.ExecutionResult.ExecutionTime = proto.Int64(conceptExecutionTime)
protoConcept.ConceptExecutionResult = conceptExecutionResult
protoConcept.ConceptStep.StepExecutionResult = conceptExecutionResult
return
}
}
}
protoConcept.ConceptExecutionResult = &gauge_messages.ProtoStepExecutionResult{ExecutionResult: &gauge_messages.ProtoExecutionResult{Failed: proto.Bool(false), ExecutionTime: proto.Int64(conceptExecutionTime)}}
protoConcept.ConceptStep.StepExecutionResult = protoConcept.ConceptExecutionResult
protoConcept.ConceptStep.StepExecutionResult.Skipped = proto.Bool(false)
}
开发者ID:andrewmkrug,项目名称:gauge,代码行数:29,代码来源:specExecutor.go
示例9: TestLeaseLengthAndRefreshInterval
func TestLeaseLengthAndRefreshInterval(t *testing.T) {
const (
leaseLength = 342
refreshInterval = 5
)
store, algo := NewLeaseStore("test"), ProportionalShare(&pb.Algorithm{
LeaseLength: proto.Int64(leaseLength),
RefreshInterval: proto.Int64(refreshInterval),
})
now := time.Now()
lease := algo(store, 100, Request{
Client: "b",
Wants: 10,
Subclients: 1,
})
leaseLengthSec := lease.Expiry.Unix() - now.Unix()
if math.Abs(float64(leaseLengthSec-leaseLength)) > 1 {
t.Errorf("lease.Expiry = %v (%d seconds), want %d seconds", lease.Expiry, leaseLengthSec, leaseLength)
}
if lease.RefreshInterval.Seconds() != refreshInterval {
t.Errorf("lease.RefreshInterval = %v, want %d seconds", lease.RefreshInterval, refreshInterval)
}
}
开发者ID:youtube,项目名称:doorman,代码行数:28,代码来源:algorithm_test.go
示例10: logf
func (c *httpContext) logf(level int64, levelName, format string, args ...interface{}) {
s := fmt.Sprintf(format, args...)
s = strings.TrimRight(s, "\n") // Remove any trailing newline characters.
log.Println(levelName + ": " + s)
// Truncate long log lines.
const maxLogLine = 8192
if len(s) > maxLogLine {
suffix := fmt.Sprintf("...(length %d)", len(s))
s = s[:maxLogLine-len(suffix)] + suffix
}
buf, err := proto.Marshal(&lpb.UserAppLogGroup{
LogLine: []*lpb.UserAppLogLine{
{
TimestampUsec: proto.Int64(time.Now().UnixNano() / 1e3),
Level: proto.Int64(level),
Message: proto.String(s),
}}})
if err != nil {
log.Printf("appengine_internal.flushLog: failed marshaling AppLogGroup: %v", err)
return
}
req := &lpb.FlushRequest{
Logs: buf,
}
res := &basepb.VoidProto{}
if err := c.Call("logservice", "Flush", req, res, nil); err != nil {
log.Printf("appengine_internal.flushLog: failed Flush RPC: %v", err)
}
}
开发者ID:odeke-em,项目名称:appengine-go,代码行数:32,代码来源:api_dev.go
示例11: Action1Handler
func Action1Handler(user *User, data []byte) {
// request body unmarshaling
req := new(gs_protocol.ReqAction1)
err := proto.Unmarshal(data, req)
gs.CheckError(err)
// TODO create business logic for Action1 Type
if DEBUG {
gs.Log("Action1 userID : ", gs.Itoa64(req.GetUserID()))
}
// broadcast message
notifyMsg := new(gs_protocol.NotifyAction1Msg)
notifyMsg.UserID = proto.Int64(user.userID)
msg, err := proto.Marshal(notifyMsg)
gs.CheckError(err)
user.SendToAll(NewMessage(user.userID, gs_protocol.Type_NotifyAction1, msg))
// response body marshaling
res := new(gs_protocol.ResAction1)
res.UserID = proto.Int64(user.userID)
res.Result = proto.Int32(1) // is success?
msg, err = proto.Marshal(res)
gs.CheckError(err)
user.Push(NewMessage(user.userID, gs_protocol.Type_DefinedAction1, msg))
}
开发者ID:ohsaean,项目名称:gogpd,代码行数:28,代码来源:handler.go
示例12: commitTransaction
func (lm *logManager) commitTransaction(tid TransactionID) error {
cm, ok := lm.currMutexes[tid]
if !ok {
return fmt.Errorf("transaction with ID %d is not currently running", tid)
}
// Write out COMMIT and END log entries
lm.addLogEntry(&pb.LogEntry{
Tid: proto.Int64(int64(tid)),
EntryType: pb.LogEntry_COMMIT.Enum(),
})
lm.addLogEntry(&pb.LogEntry{
Tid: proto.Int64(int64(tid)),
EntryType: pb.LogEntry_END.Enum(),
})
// Flush out log
if err := lm.flushLog(); err != nil {
return fmt.Errorf("error while flushing log: %v", err)
}
// Release all locks and remove from current transactions
for _, rw := range cm {
rw.unlock()
}
delete(lm.currMutexes, tid)
return nil
}
开发者ID:mDibyo,项目名称:gostore,代码行数:29,代码来源:logmanager.go
示例13: TestRunBroadcastFive
func TestRunBroadcastFive(t *testing.T) {
c := make(chan Packet, 100)
var r run
r.seqn = 1
r.out = c
r.addr = []*net.UDPAddr{
MustResolveUDPAddr("udp", "1.2.3.4:5"),
MustResolveUDPAddr("udp", "2.3.4.5:6"),
MustResolveUDPAddr("udp", "3.4.5.6:7"),
MustResolveUDPAddr("udp", "4.5.6.7:8"),
MustResolveUDPAddr("udp", "5.6.7.8:9"),
}
r.broadcast(newInvite(1))
c <- Packet{}
exp := Msg{
Seqn: proto.Int64(1),
Cmd: invite,
Crnd: proto.Int64(1),
}
addr := make([]*net.UDPAddr, len(r.addr))
for i := 0; i < len(r.addr); i++ {
p := <-c
addr[i] = p.Addr
assert.Equal(t, exp, p.Msg)
}
assert.Equal(t, Packet{}, <-c)
assert.Equal(t, r.addr, addr)
}
开发者ID:zyxar,项目名称:doozerd,代码行数:32,代码来源:run_test.go
示例14: 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
示例15: CreateHandler
func CreateHandler(user *User, data []byte) {
// request body unmarshaling
req := new(gs_protocol.ReqCreate)
err := proto.Unmarshal(data, req)
gs.CheckError(err)
if user.userID != req.GetUserID() {
if DEBUG {
gs.Log("Fail room create, user id missmatch")
}
return
}
// room create
roomID := GetRandomRoomID()
r := NewRoom(roomID)
r.users.Set(user.userID, user) // insert user
user.room = r // set room
rooms.Set(roomID, r) // set room into global shared map
if DEBUG {
gs.Log("Get rand room id : ", gs.Itoa64(roomID))
}
// response body marshaling
res := new(gs_protocol.ResCreate)
res.RoomID = proto.Int64(roomID)
res.UserID = proto.Int64(user.userID)
if DEBUG {
gs.Log("Room create, room id : ", gs.Itoa64(roomID))
}
msg, err := proto.Marshal(res)
gs.CheckError(err)
user.Push(NewMessage(user.userID, gs_protocol.Type_Create, msg))
}
开发者ID:ohsaean,项目名称:gogpd,代码行数:35,代码来源:handler.go
示例16: TestRunBroadcastThree
func TestRunBroadcastThree(t *testing.T) {
c := make(chan Packet, 100)
var r run
r.seqn = 1
r.out = c
r.addr = []*net.UDPAddr{
MustResolveUDPAddr("udp", "1.2.3.4:5"),
MustResolveUDPAddr("udp", "2.3.4.5:6"),
MustResolveUDPAddr("udp", "3.4.5.6:7"),
}
r.broadcast(newInvite(1))
c <- Packet{}
exp := msg{
Seqn: proto.Int64(1),
Cmd: invite,
Crnd: proto.Int64(1),
}
addr := make([]*net.UDPAddr, len(r.addr))
for i := 0; i < len(r.addr); i++ {
p := <-c
addr[i] = p.Addr
var got msg
err := proto.Unmarshal(p.Data, &got)
assert.Equal(t, nil, err)
assert.Equal(t, exp, got)
}
assert.Equal(t, Packet{}, <-c)
assert.Equal(t, r.addr, addr)
}
开发者ID:droxer,项目名称:doozerd,代码行数:33,代码来源:run_test.go
示例17: requestVotes
func (s *Server) requestVotes() {
theOtherNodes := s.theOtherNodes()
// if re-relect, reset the voteChan
s.getVoteResponseChan = make(chan wrappedVoteResponse, len(theOtherNodes))
for id, node := range theOtherNodes {
go func(id int32, node Node) { // send vote request simultaneously
for { // not responded, keep trying
logger.Printf("node %d send to node %d\n", s.id, id)
pb := &RequestVoteRequest{
CandidateID: proto.Int32(s.id),
Term: proto.Int64(s.currentTerm),
LastLogIndex: proto.Int64(s.log.lastLogIndex()),
LastLogTerm: proto.Int64(s.log.lastLogTerm()),
}
responseProto, err := node.rpcRequestVote(s, pb)
if err == nil {
if responseProto.GetVoteGranted() {
logger.Printf("node %d got node %d granted\n", s.id, id)
} else {
logger.Printf("node %d got node %d reject\n", s.id, id)
}
s.getVoteResponseChan <- wrappedVoteResponse{
id: id,
RequestVoteResponse: responseProto,
}
return
}
logger.Println("vote response error:", err.Error())
}
}(id, node)
}
}
开发者ID:se77en,项目名称:lilraft,代码行数:32,代码来源:server.go
示例18: Phase1RPC
// Phase1RPC handles ClassicPaxos.Phase1 rpc.
func (this *Paxos) Phase1RPC(header *msgpb.Header,
request *thispb.Phase1Request) (status error) {
if !this.IsAcceptor() {
this.Errorf("this paxos instance is not an acceptor; rejecting %s", header)
return errs.ErrInvalid
}
lock, errLock := this.ctlr.TimedLock(msg.RequestTimeout(header),
"acceptor")
if errLock != nil {
return errLock
}
defer lock.Unlock()
clientID := header.GetMessengerId()
respond := func() error {
response := thispb.Phase1Response{}
response.PromisedBallot = proto.Int64(this.promisedBallot)
if this.votedBallot >= 0 {
response.VotedBallot = proto.Int64(this.votedBallot)
response.VotedValue = this.votedValue
}
message := thispb.PaxosMessage{}
message.Phase1Response = &response
errSend := msg.SendResponseProto(this.msn, header, &message)
if errSend != nil {
this.Errorf("could not send phase1 response to %s: %v", clientID,
errSend)
return errSend
}
return nil
}
ballot := request.GetBallotNumber()
if ballot < this.promisedBallot {
this.Warningf("phase1 request from %s is ignored due to stale ballot %d",
clientID, ballot)
return respond()
}
if ballot == this.promisedBallot {
this.Warningf("duplicate phase1 request from client %s with an already "+
"promised ballot number %d", clientID, ballot)
return respond()
}
// Save the promise into the wal.
change := thispb.AcceptorChange{}
change.PromisedBallot = proto.Int64(ballot)
if err := this.doUpdateAcceptor(&change); err != nil {
this.Errorf("could not update acceptor state: %v", err)
return err
}
this.Infof("this acceptor has now promised higher ballot %d from %s", ballot,
clientID)
return respond()
}
开发者ID:bvk,项目名称:ascent,代码行数:60,代码来源:paxos.go
示例19: addExecutionTimes
func addExecutionTimes(stepExecResult *gauge_messages.ProtoStepExecutionResult, execResults ...*gauge_messages.ProtoExecutionResult) {
for _, execResult := range execResults {
currentScenarioExecTime := stepExecResult.ExecutionResult.ExecutionTime
if currentScenarioExecTime == nil {
stepExecResult.ExecutionResult.ExecutionTime = proto.Int64(execResult.GetExecutionTime())
} else {
stepExecResult.ExecutionResult.ExecutionTime = proto.Int64(*currentScenarioExecTime + execResult.GetExecutionTime())
}
}
}
开发者ID:andrewmkrug,项目名称:gauge,代码行数:10,代码来源:specExecutor.go
示例20: BuildMessage
func BuildMessage(from int, to string, data []byte, tp Msg_Type, tick int64) *Msg {
m := &Msg{
From: proto.Int64(int64(from)),
To: proto.String(to),
Tp: &tp,
D: data,
Ct: proto.Int64(tick),
}
return m
}
开发者ID:philipbo,项目名称:kodec,代码行数:10,代码来源:kodec.go
注:本文中的github.com/golang/protobuf/proto.Int64函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论