本文整理汇总了Golang中code/google/com/p/gogoprotobuf/proto.Uint64函数的典型用法代码示例。如果您正苦于以下问题:Golang Uint64函数的具体用法?Golang Uint64怎么用?Golang Uint64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Uint64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newLogEntry
// Creates a new log entry associated with a log.
func newLogEntry(log *Log, event *ev, index uint64, term uint64, command Command) (*LogEntry, error) {
var buf bytes.Buffer
var commandName string
if command != nil {
commandName = command.CommandName()
if encoder, ok := command.(CommandEncoder); ok {
if err := encoder.Encode(&buf); err != nil {
return nil, err
}
} else {
json.NewEncoder(&buf).Encode(command)
}
}
pb := &protobuf.LogEntry{
Index: proto.Uint64(index),
Term: proto.Uint64(term),
CommandName: proto.String(commandName),
Command: buf.Bytes(),
}
e := &LogEntry{
pb: pb,
log: log,
event: event,
}
return e, nil
}
示例2: Encode
// Encodes the SnapshotRecoveryRequest to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (req *SnapshotRecoveryRequest) Encode(w io.Writer) (int, error) {
protoPeers := make([]*protobuf.SnapshotRecoveryRequest_Peer, len(req.Peers))
for i, peer := range req.Peers {
protoPeers[i] = &protobuf.SnapshotRecoveryRequest_Peer{
Name: proto.String(peer.Name),
ConnectionString: proto.String(peer.ConnectionString),
}
}
pb := &protobuf.SnapshotRecoveryRequest{
LeaderName: proto.String(req.LeaderName),
LastIndex: proto.Uint64(req.LastIndex),
LastTerm: proto.Uint64(req.LastTerm),
Peers: protoPeers,
State: req.State,
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
}
示例3: handleLimitBandwidth
func (s *WardenServer) handleLimitBandwidth(request *protocol.LimitBandwidthRequest) (proto.Message, error) {
handle := request.GetHandle()
rate := request.GetRate()
burst := request.GetBurst()
container, err := s.backend.Lookup(handle)
if err != nil {
return nil, err
}
s.bomberman.Pause(container.Handle())
defer s.bomberman.Unpause(container.Handle())
err = container.LimitBandwidth(warden.BandwidthLimits{
RateInBytesPerSecond: rate,
BurstRateInBytesPerSecond: burst,
})
if err != nil {
return nil, err
}
limits, err := container.CurrentBandwidthLimits()
if err != nil {
return nil, err
}
return &protocol.LimitBandwidthResponse{
Rate: proto.Uint64(limits.RateInBytesPerSecond),
Burst: proto.Uint64(limits.BurstRateInBytesPerSecond),
}, nil
}
示例4: NewHeartbeat
func NewHeartbeat(sentCount, receivedCount, errorCount uint64) *events.Heartbeat {
return &events.Heartbeat{
SentCount: proto.Uint64(sentCount),
ReceivedCount: proto.Uint64(receivedCount),
ErrorCount: proto.Uint64(errorCount),
}
}
示例5: handleCapacity
func (s *WardenServer) handleCapacity(echo *protocol.CapacityRequest) (proto.Message, error) {
capacity, err := s.backend.Capacity()
if err != nil {
return nil, err
}
return &protocol.CapacityResponse{
MemoryInBytes: proto.Uint64(capacity.MemoryInBytes),
DiskInBytes: proto.Uint64(capacity.DiskInBytes),
MaxContainers: proto.Uint64(capacity.MaxContainers),
}, nil
}
示例6: newAppendEntriesResponse
// Creates a new AppendEntries response.
func newAppendEntriesResponse(term uint64, success bool, index uint64, commitIndex uint64) *AppendEntriesResponse {
pb := &protobuf.AppendEntriesResponse{
Term: proto.Uint64(term),
Index: proto.Uint64(index),
Success: proto.Bool(success),
CommitIndex: proto.Uint64(commitIndex),
}
return &AppendEntriesResponse{
pb: pb,
}
}
示例7: Encode
// Encodes the RequestVoteRequest to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (req *RequestVoteRequest) Encode(w io.Writer) (int, error) {
pb := &protobuf.RequestVoteRequest{
Term: proto.Uint64(req.Term),
LastLogIndex: proto.Uint64(req.LastLogIndex),
LastLogTerm: proto.Uint64(req.LastLogTerm),
CandidateName: proto.String(req.CandidateName),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
}
示例8: handleLimitCpu
func (s *WardenServer) handleLimitCpu(request *protocol.LimitCpuRequest) (proto.Message, error) {
handle := request.GetHandle()
limitInShares := request.GetLimitInShares()
container, err := s.backend.Lookup(handle)
if err != nil {
return nil, err
}
s.bomberman.Pause(container.Handle())
defer s.bomberman.Unpause(container.Handle())
if request.LimitInShares != nil {
err = container.LimitCPU(warden.CPULimits{
LimitInShares: limitInShares,
})
if err != nil {
return nil, err
}
}
limits, err := container.CurrentCPULimits()
if err != nil {
return nil, err
}
return &protocol.LimitCpuResponse{
LimitInShares: proto.Uint64(limits.LimitInShares),
}, nil
}
示例9: Encode
// Encodes the AppendEntriesRequest to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (req *AppendEntriesRequest) Encode(w io.Writer) (int, error) {
pb := &protobuf.AppendEntriesRequest{
Term: proto.Uint64(req.Term),
PrevLogIndex: proto.Uint64(req.PrevLogIndex),
PrevLogTerm: proto.Uint64(req.PrevLogTerm),
CommitIndex: proto.Uint64(req.CommitIndex),
LeaderName: proto.String(req.LeaderName),
Entries: req.Entries,
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
}
示例10: Encode
// Encodes the RequestVoteResponse to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (resp *RequestVoteResponse) Encode(w io.Writer) (int, error) {
pb := &protobuf.RequestVoteResponse{
Term: proto.Uint64(resp.Term),
VoteGranted: proto.Bool(resp.VoteGranted),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
}
示例11: LimitDisk
func (c *Connection) LimitDisk(handle string, limit uint64) (*warden.LimitDiskResponse, error) {
res, err := c.RoundTrip(
&warden.LimitDiskRequest{
Handle: proto.String(handle),
ByteLimit: proto.Uint64(limit),
},
&warden.LimitDiskResponse{},
)
if err != nil {
return nil, err
}
return res.(*warden.LimitDiskResponse), nil
}
示例12:
It("should stop the container", func() {
_, err := connection.Destroy("foo")
Ω(err).ShouldNot(HaveOccurred())
assertWriteBufferContains(&warden.DestroyRequest{
Handle: proto.String("foo"),
})
})
})
Describe("Limiting Memory", func() {
Describe("Setting the memory limit", func() {
BeforeEach(func() {
wardenMessages = append(wardenMessages,
&warden.LimitMemoryResponse{LimitInBytes: proto.Uint64(40)},
)
})
It("should limit memory", func() {
res, err := connection.LimitMemory("foo", 42)
Ω(err).ShouldNot(HaveOccurred())
Ω(res.GetLimitInBytes()).Should(BeNumerically("==", 40))
assertWriteBufferContains(&warden.LimitMemoryRequest{
Handle: proto.String("foo"),
LimitInBytes: proto.Uint64(42),
})
})
})
示例13: handleLimitDisk
func (s *WardenServer) handleLimitDisk(request *protocol.LimitDiskRequest) (proto.Message, error) {
handle := request.GetHandle()
blockSoft := request.GetBlockSoft()
blockHard := request.GetBlockHard()
inodeSoft := request.GetInodeSoft()
inodeHard := request.GetInodeHard()
byteSoft := request.GetByteSoft()
byteHard := request.GetByteHard()
settingLimit := false
if request.BlockSoft != nil || request.BlockHard != nil ||
request.InodeSoft != nil || request.InodeHard != nil ||
request.ByteSoft != nil || request.ByteHard != nil {
settingLimit = true
}
if request.Block != nil {
blockHard = request.GetBlock()
settingLimit = true
}
if request.BlockLimit != nil {
blockHard = request.GetBlockLimit()
settingLimit = true
}
if request.Inode != nil {
inodeHard = request.GetInode()
settingLimit = true
}
if request.InodeLimit != nil {
inodeHard = request.GetInodeLimit()
settingLimit = true
}
if request.Byte != nil {
byteHard = request.GetByte()
settingLimit = true
}
if request.ByteLimit != nil {
byteHard = request.GetByteLimit()
settingLimit = true
}
container, err := s.backend.Lookup(handle)
if err != nil {
return nil, err
}
s.bomberman.Pause(container.Handle())
defer s.bomberman.Unpause(container.Handle())
if settingLimit {
err = container.LimitDisk(warden.DiskLimits{
BlockSoft: blockSoft,
BlockHard: blockHard,
InodeSoft: inodeSoft,
InodeHard: inodeHard,
ByteSoft: byteSoft,
ByteHard: byteHard,
})
if err != nil {
return nil, err
}
}
limits, err := container.CurrentDiskLimits()
if err != nil {
return nil, err
}
return &protocol.LimitDiskResponse{
BlockSoft: proto.Uint64(limits.BlockSoft),
BlockHard: proto.Uint64(limits.BlockHard),
InodeSoft: proto.Uint64(limits.InodeSoft),
InodeHard: proto.Uint64(limits.InodeHard),
ByteSoft: proto.Uint64(limits.ByteSoft),
ByteHard: proto.Uint64(limits.ByteHard),
}, nil
}
示例14: handleInfo
func (s *WardenServer) handleInfo(request *protocol.InfoRequest) (proto.Message, error) {
handle := request.GetHandle()
container, err := s.backend.Lookup(handle)
if err != nil {
return nil, err
}
s.bomberman.Pause(container.Handle())
defer s.bomberman.Unpause(container.Handle())
info, err := container.Info()
if err != nil {
return nil, err
}
properties := []*protocol.Property{}
for key, val := range info.Properties {
properties = append(properties, &protocol.Property{
Key: proto.String(key),
Value: proto.String(val),
})
}
processIDs := make([]uint64, len(info.ProcessIDs))
for i, processID := range info.ProcessIDs {
processIDs[i] = uint64(processID)
}
return &protocol.InfoResponse{
State: proto.String(info.State),
Events: info.Events,
HostIp: proto.String(info.HostIP),
ContainerIp: proto.String(info.ContainerIP),
ContainerPath: proto.String(info.ContainerPath),
ProcessIds: processIDs,
Properties: properties,
MemoryStat: &protocol.InfoResponse_MemoryStat{
Cache: proto.Uint64(info.MemoryStat.Cache),
Rss: proto.Uint64(info.MemoryStat.Rss),
MappedFile: proto.Uint64(info.MemoryStat.MappedFile),
Pgpgin: proto.Uint64(info.MemoryStat.Pgpgin),
Pgpgout: proto.Uint64(info.MemoryStat.Pgpgout),
Swap: proto.Uint64(info.MemoryStat.Swap),
Pgfault: proto.Uint64(info.MemoryStat.Pgfault),
Pgmajfault: proto.Uint64(info.MemoryStat.Pgmajfault),
InactiveAnon: proto.Uint64(info.MemoryStat.InactiveAnon),
ActiveAnon: proto.Uint64(info.MemoryStat.ActiveAnon),
InactiveFile: proto.Uint64(info.MemoryStat.InactiveFile),
ActiveFile: proto.Uint64(info.MemoryStat.ActiveFile),
Unevictable: proto.Uint64(info.MemoryStat.Unevictable),
HierarchicalMemoryLimit: proto.Uint64(info.MemoryStat.HierarchicalMemoryLimit),
HierarchicalMemswLimit: proto.Uint64(info.MemoryStat.HierarchicalMemswLimit),
TotalCache: proto.Uint64(info.MemoryStat.TotalCache),
TotalRss: proto.Uint64(info.MemoryStat.TotalRss),
TotalMappedFile: proto.Uint64(info.MemoryStat.TotalMappedFile),
TotalPgpgin: proto.Uint64(info.MemoryStat.TotalPgpgin),
TotalPgpgout: proto.Uint64(info.MemoryStat.TotalPgpgout),
TotalSwap: proto.Uint64(info.MemoryStat.TotalSwap),
TotalPgfault: proto.Uint64(info.MemoryStat.TotalPgfault),
TotalPgmajfault: proto.Uint64(info.MemoryStat.TotalPgmajfault),
TotalInactiveAnon: proto.Uint64(info.MemoryStat.TotalInactiveAnon),
TotalActiveAnon: proto.Uint64(info.MemoryStat.TotalActiveAnon),
TotalInactiveFile: proto.Uint64(info.MemoryStat.TotalInactiveFile),
TotalActiveFile: proto.Uint64(info.MemoryStat.TotalActiveFile),
TotalUnevictable: proto.Uint64(info.MemoryStat.TotalUnevictable),
},
CpuStat: &protocol.InfoResponse_CpuStat{
Usage: proto.Uint64(info.CPUStat.Usage),
User: proto.Uint64(info.CPUStat.User),
System: proto.Uint64(info.CPUStat.System),
},
DiskStat: &protocol.InfoResponse_DiskStat{
BytesUsed: proto.Uint64(info.DiskStat.BytesUsed),
InodesUsed: proto.Uint64(info.DiskStat.InodesUsed),
},
BandwidthStat: &protocol.InfoResponse_BandwidthStat{
InRate: proto.Uint64(info.BandwidthStat.InRate),
InBurst: proto.Uint64(info.BandwidthStat.InBurst),
OutRate: proto.Uint64(info.BandwidthStat.OutRate),
OutBurst: proto.Uint64(info.BandwidthStat.OutBurst),
},
}, nil
}
示例15: NewUUID
func NewUUID(id *uuid.UUID) *events.UUID {
return &events.UUID{Low: proto.Uint64(binary.LittleEndian.Uint64(id[:8])), High: proto.Uint64(binary.LittleEndian.Uint64(id[8:]))}
}