本文整理匯總了Golang中goprotobuf/googlecode/com/hg/proto.Int64函數的典型用法代碼示例。如果您正苦於以下問題:Golang Int64函數的具體用法?Golang Int64怎麽用?Golang Int64使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Int64函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRunBroadcastFive
func TestRunBroadcastFive(t *testing.T) {
c := make(chan Packet, 100)
sentinel := Packet{Addr: "sentinel"}
var r run
r.seqn = 1
r.out = c
r.addr = []string{"v", "w", "x", "y", "z"}
r.broadcast(newInvite(1))
c <- sentinel
exp := msg{
Seqn: proto.Int64(1),
Cmd: invite,
Crnd: proto.Int64(1),
}
addrs := make([]string, len(r.addr))
for i := 0; i < len(r.addr); i++ {
p := <-c
addrs[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, sentinel, <-c)
assert.Equal(t, r.addr, addrs)
}
示例2: TestRunBroadcastThree
func TestRunBroadcastThree(t *testing.T) {
c := make(chan Packet, 100)
sentinel := Packet{Addr: "sentinel"}
var r run
r.seqn = 1
r.out = c
r.addrs = map[string]bool{
"x": true,
"y": true,
"z": true,
}
r.broadcast(newInvite(1))
c <- sentinel
exp := msg{
Seqn: proto.Int64(1),
Cmd: invite,
Crnd: proto.Int64(1),
}
addrs := map[string]bool{}
for i := 0; i < len(r.addrs); i++ {
p := <-c
addrs[p.Addr] = true
var got msg
err := proto.Unmarshal(p.Data, &got)
assert.Equal(t, nil, err)
assert.Equal(t, exp, got)
}
assert.Equal(t, sentinel, <-c)
assert.Equal(t, r.addrs, addrs)
}
示例3: TestRunBroadcastFive
func TestRunBroadcastFive(t *testing.T) {
c := make(chan Packet, 100)
var r run
r.seqn = 1
r.out = c
r.addr = []*net.UDPAddr{
&net.UDPAddr{net.IP{1, 2, 3, 4}, 5},
&net.UDPAddr{net.IP{2, 3, 4, 5}, 6},
&net.UDPAddr{net.IP{3, 4, 5, 6}, 7},
&net.UDPAddr{net.IP{4, 5, 6, 7}, 8},
&net.UDPAddr{net.IP{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
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)
}
示例4: TestRecvPacket
func TestRecvPacket(t *testing.T) {
q := new(vector.Vector)
recvPacket(q, Packet{"x", mustMarshal(&msg{Seqn: proto.Int64(1)})})
recvPacket(q, Packet{"x", mustMarshal(&msg{Seqn: proto.Int64(2)})})
recvPacket(q, Packet{"x", mustMarshal(&msg{Seqn: proto.Int64(3)})})
assert.Equal(t, 3, q.Len())
}
示例5: Divide
func (*MyCalcService) Divide(req *CalcRequest, resp *CalcResponse) (err os.Error) {
resp.Result = proto.Int64(0)
defer func() {
if x := recover(); x != nil {
if ex, ok := x.(os.Error); ok {
err = ex
} else {
err = os.ErrorString(fmt.Sprint(x))
}
}
}()
resp.Result = proto.Int64(proto.GetInt64(req.A) / proto.GetInt64(req.B))
resp.Remainder = proto.Int64(proto.GetInt64(req.A) % proto.GetInt64(req.B))
return
}
示例6: runPlugin
// chasing a moving target with exec here. currently it's kind of
// clumsy to pull out the return code. with luck the target will
// move again in a way i like.
func runPlugin(cmd, env []string, timeout int64) (result *CheckResult) {
var output bytes.Buffer
rc := 0
log.Printf("running check %s", cmd)
/* c := exec.Command(cmd[0], cmd...)*/
c := exec.Command(cmd[0], cmd[1:]...)
c.Stdout = &output
starttime := time.Nanoseconds()
err := c.Start()
if err != nil {
log.Fatal("Error running command ", cmd, ": ", err)
}
defer c.Process.Release()
timer := time.AfterFunc(timeout, func() { c.Process.Kill() })
err = c.Wait()
timer.Stop()
endtime := time.Nanoseconds()
/* log.Print(msg)*/
if err != nil {
if msg, ok := err.(*os.Waitmsg); ok {
rc = msg.ExitStatus()
} else {
log.Print("Error running command ", cmd, ": ", err)
}
}
result = &CheckResult{
StartTimestamp: proto.Int64(starttime),
EndTimestamp: proto.Int64(endtime),
Status: NewCheckStatus(CheckStatus(rc)),
CheckPassive: proto.Bool(*flagPassive),
}
switch rc {
case 0, 1, 2, 3:
// this is ok!
log.Printf("%s: returned %s", cmd, CheckStatus_name[int32(rc)])
result.Status = NewCheckStatus(CheckStatus(rc))
result.CheckOutput = proto.String(string(bytes.TrimSpace(output.Bytes())))
break
default:
// XXX check for timeout/sig9, presently assumed
log.Printf("%s: return code %d", cmd, rc)
result.Status = NewCheckStatus(CheckStatus_UNKNOWN)
result.CheckOutput = proto.String(fmt.Sprintf("UNKNOWN: Command timed out after %d seconds\n", *flagCmdTimeout) + string(bytes.TrimSpace(output.Bytes())))
}
return result
}
示例7: NewWavelet
func NewWavelet(url *WaveUrl) (result *Wavelet) {
result = &Wavelet{Url: url}
result.HashedVersion.HistoryHash = []byte(url.String())
result.HashedVersion.Version = proto.Int64(0)
result.Documents = make(map[string]*WaveletDocument)
return result
}
示例8: TestManagerTickQueue
func TestManagerTickQueue(t *testing.T) {
ticker := make(chan int64)
st := store.New()
defer close(st.Ops)
in := make(chan Packet)
cfg := &Config{
Alpha: 1,
Store: st,
In: in,
Ticker: ticker,
Out: make(chan Packet, 100),
}
m := NewManager(cfg)
st.Ops <- store.Op{
Seqn: 1,
Mut: store.MustEncodeSet(node+"/a/addr", "x", 0),
}
for (<-m.Stats).Runs < 1 {
}
// get it to tick for seqn 2
in <- Packet{Data: mustMarshal(&msg{Seqn: proto.Int64(2), Cmd: propose})}
assert.Equal(t, 1, (<-m.Stats).WaitTicks)
ticker <- time.Nanoseconds() + initialWaitBound*2
assert.Equal(t, int64(1), (<-m.Stats).TotalTicks)
}
示例9: TestManagerDeletesSuccessfulRun
func TestManagerDeletesSuccessfulRun(t *testing.T) {
st := store.New()
defer close(st.Ops)
in := make(chan Packet)
out := make(chan Packet, 100)
cfg := &Config{
Alpha: 1,
Store: st,
In: in,
Out: out,
Ops: st.Ops,
}
m := NewManager(cfg)
st.Ops <- store.Op{
Seqn: 1,
Mut: store.MustEncodeSet(node+"/a/addr", "x", 0),
}
for (<-m.Stats).TotalRuns < 1 {
}
in <- Packet{
Data: mustMarshal(&msg{Seqn: proto.Int64(2), Cmd: learn, Value: []byte("foo")}),
Addr: "127.0.0.1:9999",
}
for (<-m.Stats).TotalRuns < 2 {
}
assert.Equal(t, 1, (<-m.Stats).Runs)
}
示例10: fetch
// fetch fetches readBufferSize bytes starting at the given offset. On success,
// the data is saved as r.buf.
func (r *reader) fetch(off int64) error {
req := &pb.FetchDataRequest{
BlobKey: proto.String(string(r.blobKey)),
StartIndex: proto.Int64(off),
EndIndex: proto.Int64(off + readBufferSize - 1), // EndIndex is inclusive.
}
res := &pb.FetchDataResponse{}
if err := r.c.Call("blobstore", "FetchData", req, res, nil); err != nil {
return err
}
if len(res.Data) == 0 {
return io.EOF
}
r.buf, r.r, r.off = res.Data, 0, off
return nil
}
示例11: UploadURL
// UploadURL creates an upload URL for the form that the user will
// fill out, passing the application path to load when the POST of the
// form is completed. These URLs expire and should not be reused. The
// opts parameter may be nil.
func UploadURL(c appengine.Context, successPath string, opts *UploadURLOptions) (*url.URL, error) {
req := &pb.CreateUploadURLRequest{
SuccessPath: proto.String(successPath),
}
if opts != nil {
if opts.MaxUploadBytes != 0 {
req.MaxUploadSizeBytes = proto.Int64(opts.MaxUploadBytes)
}
if opts.MaxUploadBytesPerBlob != 0 {
req.MaxUploadSizePerBlobBytes = proto.Int64(opts.MaxUploadBytesPerBlob)
}
}
res := &pb.CreateUploadURLResponse{}
if err := c.Call("blobstore", "CreateUploadURL", req, res, nil); err != nil {
return nil, err
}
return url.Parse(*res.Url)
}
示例12: TestManagerPacketQueue
func TestManagerPacketQueue(t *testing.T) {
in := make(chan Packet)
st := store.New()
out := make(chan Packet, 100)
m := newManager("", 0, nil, in, nil, nil, nil, 0, st, out)
in <- Packet{"x", mustMarshal(&msg{Seqn: proto.Int64(1)})}
assert.Equal(t, 1, (<-m).WaitPackets)
}
示例13: TestRunVoteDelivered
func TestRunVoteDelivered(t *testing.T) {
r := run{}
r.out = make(chan Packet, 100)
r.ops = make(chan store.Op, 100)
r.l.init(1)
p := packet{
msg: msg{
Seqn: proto.Int64(1),
Cmd: vote,
Vrnd: proto.Int64(1),
Value: []byte("foo"),
},
Addr: "X",
}
r.update(p, new(vector.Vector))
assert.Equal(t, true, r.l.done)
assert.Equal(t, "foo", r.l.v)
}
示例14: TestRunSendsAcceptorPacket
func TestRunSendsAcceptorPacket(t *testing.T) {
c := make(chan Packet, 100)
var r run
r.out = c
r.addr = []string{"x", "y"}
var got msg
exp := msg{
Seqn: proto.Int64(0),
Cmd: rsvp,
Crnd: proto.Int64(1),
Vrnd: proto.Int64(0),
}
r.update(packet{msg: *newInviteSeqn1(1)}, new(vector.Vector))
<-c
err := proto.Unmarshal((<-c).Data, &got)
assert.Equal(t, nil, err)
assert.Equal(t, exp, got)
assert.Equal(t, 0, len(c))
}
示例15: TestRunSendsCoordPacket
func TestRunSendsCoordPacket(t *testing.T) {
c := make(chan Packet, 100)
var r run
r.c.crnd = 1
r.out = c
r.addr = []string{"x", "y"}
var got msg
exp := msg{
Seqn: proto.Int64(0),
Cmd: invite,
Crnd: proto.Int64(1),
}
r.update(packet{msg: *newPropose("foo")}, new(vector.Vector))
<-c
err := proto.Unmarshal((<-c).Data, &got)
assert.Equal(t, nil, err)
assert.Equal(t, exp, got)
assert.Equal(t, 0, len(c))
}