本文整理汇总了Golang中github.com/golang/protobuf/proto.Int64函数的典型用法代码示例。如果您正苦于以下问题:Golang Int64函数的具体用法?Golang Int64怎么用?Golang Int64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Int64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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
}
示例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")
}
}
示例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)),
}
}
示例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)
}
}
示例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)
}
}
}
示例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
}
示例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)
}
示例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)
}
}
示例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)
}
}
示例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))
}
示例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
}
示例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)
}
示例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
}
示例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))
}