本文整理汇总了Golang中github.com/golang/protobuf/proto.Int函数的典型用法代码示例。如果您正苦于以下问题:Golang Int函数的具体用法?Golang Int怎么用?Golang Int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Int函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestToVerifyXmlContentForDataTableDrivenExecution
func (s *MySuite) TestToVerifyXmlContentForDataTableDrivenExecution(c *C) {
value := gauge_messages.ProtoItem_TableDrivenScenario
scenario := gauge_messages.ProtoScenario{Failed: proto.Bool(false), ScenarioHeading: proto.String("Scenario")}
scenario1 := gauge_messages.ProtoScenario{Failed: proto.Bool(false), ScenarioHeading: proto.String("Scenario")}
item := &gauge_messages.ProtoItem{TableDrivenScenario: &gauge_messages.ProtoTableDrivenScenario{Scenarios: []*gauge_messages.ProtoScenario{&scenario, &scenario1}}, ItemType: &value}
spec := &gauge_messages.ProtoSpec{SpecHeading: proto.String("HEADING"), FileName: proto.String("FILENAME"), Items: []*gauge_messages.ProtoItem{item}}
specResult := &gauge_messages.ProtoSpecResult{ProtoSpec: spec, ScenarioCount: proto.Int(1), Failed: proto.Bool(false)}
suiteResult := &gauge_messages.ProtoSuiteResult{SpecResults: []*gauge_messages.ProtoSpecResult{specResult}}
message := &gauge_messages.SuiteExecutionResult{SuiteResult: suiteResult}
builder := &XmlBuilder{currentId: 0}
bytes, err := builder.getXmlContent(message)
var suites JUnitTestSuites
xml.Unmarshal(bytes, &suites)
c.Assert(err, Equals, nil)
c.Assert(len(suites.Suites), Equals, 1)
c.Assert(suites.Suites[0].Errors, Equals, 0)
c.Assert(suites.Suites[0].Failures, Equals, 0)
c.Assert(suites.Suites[0].Package, Equals, "FILENAME")
c.Assert(suites.Suites[0].Name, Equals, "HEADING")
c.Assert(suites.Suites[0].Tests, Equals, 2)
c.Assert(suites.Suites[0].Timestamp, Equals, builder.suites.Suites[0].Timestamp)
c.Assert(suites.Suites[0].SystemError.Contents, Equals, "")
c.Assert(suites.Suites[0].SystemOutput.Contents, Equals, "")
c.Assert(len(suites.Suites[0].TestCases), Equals, 2)
c.Assert(suites.Suites[0].TestCases[0].Name, Equals, "Scenario 0")
c.Assert(suites.Suites[0].TestCases[1].Name, Equals, "Scenario 1")
}
开发者ID:manuviswam,项目名称:xml-report,代码行数:29,代码来源:xmlReportBuilder_test.go
示例2: TestToVerifyXmlContentForFailingExecutionResult
func (s *MySuite) TestToVerifyXmlContentForFailingExecutionResult(c *C) {
value := gauge_messages.ProtoItem_Scenario
item := &gauge_messages.ProtoItem{Scenario: &gauge_messages.ProtoScenario{Failed: proto.Bool(true), ScenarioHeading: proto.String("Scenario1")}, ItemType: &value}
spec := &gauge_messages.ProtoSpec{SpecHeading: proto.String("HEADING"), FileName: proto.String("FILENAME"), Items: []*gauge_messages.ProtoItem{item}}
specResult := &gauge_messages.ProtoSpecResult{ProtoSpec: spec, ScenarioCount: proto.Int(1), Failed: proto.Bool(true), ScenarioFailedCount: proto.Int(1)}
suiteResult := &gauge_messages.ProtoSuiteResult{SpecResults: []*gauge_messages.ProtoSpecResult{specResult}}
message := &gauge_messages.SuiteExecutionResult{SuiteResult: suiteResult}
builder := &XmlBuilder{currentId: 0}
bytes, err := builder.getXmlContent(message)
var suites JUnitTestSuites
xml.Unmarshal(bytes, &suites)
c.Assert(err, Equals, nil)
c.Assert(len(suites.Suites), Equals, 1)
// spec1 || testSuite
c.Assert(suites.Suites[0].Errors, Equals, 0)
c.Assert(suites.Suites[0].Failures, Equals, 1)
c.Assert(suites.Suites[0].Package, Equals, "FILENAME")
c.Assert(suites.Suites[0].Name, Equals, "HEADING")
c.Assert(suites.Suites[0].Tests, Equals, 1)
c.Assert(suites.Suites[0].Timestamp, Equals, builder.suites.Suites[0].Timestamp)
c.Assert(suites.Suites[0].SystemError.Contents, Equals, "")
c.Assert(suites.Suites[0].SystemOutput.Contents, Equals, "")
// scenario1 of spec1 || testCase
c.Assert(len(suites.Suites[0].TestCases), Equals, 1)
c.Assert(suites.Suites[0].TestCases[0].Classname, Equals, "HEADING")
c.Assert(suites.Suites[0].TestCases[0].Name, Equals, "Scenario1")
c.Assert(suites.Suites[0].TestCases[0].Failure.Message, Equals, "")
c.Assert(suites.Suites[0].TestCases[0].Failure.Contents, Equals, "")
}
开发者ID:manuviswam,项目名称:xml-report,代码行数:31,代码来源:xmlReportBuilder_test.go
示例3: commitRow
func (rpc *themisRPC) commitRow(tbl, row []byte, mutations []*columnMutation,
prewriteTs, commitTs uint64, primaryOffset int) error {
req := &ThemisCommitRequest{}
req.ThemisCommit = &ThemisCommit{
Row: row,
PrewriteTs: pb.Uint64(prewriteTs),
CommitTs: pb.Uint64(commitTs),
PrimaryIndex: pb.Int(primaryOffset),
}
for _, m := range mutations {
req.ThemisCommit.Mutations = append(req.ThemisCommit.Mutations, m.toCell())
}
var res ThemisCommitResponse
err := rpc.call("commitRow", tbl, row, req, &res)
if err != nil {
return errors.Trace(err)
}
ok := res.GetResult()
if !ok {
if primaryOffset == -1 {
return errors.Errorf("commit secondary failed, tbl: %s row: %q ts: %d", tbl, row, commitTs)
}
return errors.Errorf("commit primary failed, tbl: %s row: %q ts: %d", tbl, row, commitTs)
}
return nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:27,代码来源:themis_rpc.go
示例4: EncodeMaster
// EncodeMaster encodes information about a ResourceMaster as a protobuf.
func (m *ResourceMaster) EncodeMaster() ([]byte, error) {
p := &ResourceMasterInfo{
PrinName: proto.String(m.ProgramName),
BaseDirectoryName: proto.String(m.BaseDirectory),
NumFileInfos: proto.Int(len(m.Resources)),
}
return proto.Marshal(p)
}
开发者ID:kevinawalsh,项目名称:cloudproxy,代码行数:9,代码来源:resources.go
示例5: prewriteRow
func (rpc *themisRPC) prewriteRow(tbl []byte, row []byte, mutations []*columnMutation, prewriteTs uint64, primaryLockBytes []byte, secondaryLockBytes []byte, primaryOffset int) (Lock, error) {
var cells []*proto.Cell
request := &ThemisPrewriteRequest{
PrewriteTs: pb.Uint64(prewriteTs),
PrimaryLock: primaryLockBytes,
SecondaryLock: secondaryLockBytes,
PrimaryIndex: pb.Int(primaryOffset),
}
request.ThemisPrewrite = &ThemisPrewrite{
Row: row,
}
if primaryLockBytes == nil {
request.PrimaryLock = []byte("")
}
if secondaryLockBytes == nil {
request.SecondaryLock = []byte("")
}
for _, m := range mutations {
cells = append(cells, m.toCell())
}
request.ThemisPrewrite.Mutations = cells
var res ThemisPrewriteResponse
err := rpc.call("prewriteRow", tbl, row, request, &res)
if err != nil {
return nil, errors.Trace(err)
}
b := res.ThemisPrewriteResult
if b == nil {
// if lock is empty, means we got the lock, otherwise some one else had
// locked this row, and the lock should return in rpc result
return nil, nil
}
// Oops, someone else have already locked this row.
commitTs := b.GetNewerWriteTs()
if commitTs != 0 {
log.Errorf("write conflict, encounter write with larger timestamp than prewriteTs=%d, commitTs=%d, row=%s", prewriteTs, commitTs, string(row))
return nil, kv.ErrLockConflict
}
l, err := parseLockFromBytes(b.ExistLock)
if err != nil {
return nil, errors.Trace(err)
}
col := &hbase.ColumnCoordinate{
Table: tbl,
Row: row,
Column: hbase.Column{
Family: b.Family,
Qual: b.Qualifier,
},
}
l.SetCoordinate(col)
return l, nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:57,代码来源:themis_rpc.go
示例6: EncodeResource
// EncodeResource creates a protobuf that represents a resource.
// TODO(tmroeder): map the types and statuses to protobuf enums properly.
func (r *Resource) EncodeResource() ([]byte, error) {
m := &ResourceInfo{
Name: proto.String(r.Name),
Type: proto.Int32(int32(r.Type)),
Status: proto.Int32(int32(r.Status)),
Location: proto.String(r.Location),
Size: proto.Int(r.Size),
Owner: proto.String(r.Owner),
}
return proto.Marshal(m)
}
开发者ID:kevinawalsh,项目名称:cloudproxy,代码行数:13,代码来源:resources.go
示例7: batchCommitSecondaryRows
func (rpc *themisRPC) batchCommitSecondaryRows(tbl []byte, rowMs map[string]*rowMutation, prewriteTs, commitTs uint64) error {
req := &ThemisBatchCommitSecondaryRequest{}
i := 0
var lastRow []byte
req.ThemisCommit = make([]*ThemisCommit, len(rowMs))
for row, rowM := range rowMs {
var cells []*proto.Cell
for col, m := range rowM.mutations {
cells = append(cells, toCellFromRowM(col, m))
}
req.ThemisCommit[i] = &ThemisCommit{
Row: []byte(row),
Mutations: cells,
PrewriteTs: pb.Uint64(prewriteTs),
CommitTs: pb.Uint64(commitTs),
PrimaryIndex: pb.Int(-1),
}
i++
lastRow = []byte(row)
}
var res ThemisBatchCommitSecondaryResponse
err := rpc.call("batchCommitSecondaryRows", tbl, lastRow, req, &res)
if err != nil {
return errors.Trace(err)
}
log.Info("call batch commit secondary rows", len(req.ThemisCommit))
cResult := res.BatchCommitSecondaryResult
if cResult != nil && len(cResult) > 0 {
errorInfo := "commit failed, tbl:" + string(tbl)
for _, r := range cResult {
errorInfo += (" row:" + string(r.Row))
}
return errors.New(fmt.Sprintf("%s, commitTs:%d", errorInfo, commitTs))
}
return nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:40,代码来源:themis_rpc.go
示例8: Do
func (s *migrationSourceWs) Do() shared.OperationResult {
<-s.allConnected
criuType := CRIUType_CRIU_RSYNC.Enum()
if !s.live {
criuType = nil
}
idmaps := make([]*IDMapType, 0)
if s.idmapset != nil {
for _, ctnIdmap := range s.idmapset.Idmap {
idmap := IDMapType{
Isuid: proto.Bool(ctnIdmap.Isuid),
Isgid: proto.Bool(ctnIdmap.Isgid),
Hostid: proto.Int(ctnIdmap.Hostid),
Nsid: proto.Int(ctnIdmap.Nsid),
Maprange: proto.Int(ctnIdmap.Maprange),
}
idmaps = append(idmaps, &idmap)
}
}
header := MigrationHeader{
Fs: MigrationFSType_RSYNC.Enum(),
Criu: criuType,
Idmap: idmaps,
}
if err := s.send(&header); err != nil {
s.sendControl(err)
return shared.OperationError(err)
}
if err := s.recv(&header); err != nil {
s.sendControl(err)
return shared.OperationError(err)
}
if *header.Fs != MigrationFSType_RSYNC {
err := fmt.Errorf("Formats other than rsync not understood")
s.sendControl(err)
return shared.OperationError(err)
}
if s.live {
if header.Criu == nil {
err := fmt.Errorf("Got no CRIU socket type for live migration")
s.sendControl(err)
return shared.OperationError(err)
} else if *header.Criu != CRIUType_CRIU_RSYNC {
err := fmt.Errorf("Formats other than criu rsync not understood")
s.sendControl(err)
return shared.OperationError(err)
}
checkpointDir, err := ioutil.TempDir("", "lxd_migration_")
if err != nil {
s.sendControl(err)
return shared.OperationError(err)
}
defer os.RemoveAll(checkpointDir)
opts := lxc.CheckpointOptions{Stop: true, Directory: checkpointDir, Verbose: true}
err = s.container.Checkpoint(opts)
if err2 := CollectCRIULogFile(s.container, checkpointDir, "migration", "dump"); err2 != nil {
shared.Debugf("Error collecting checkpoint log file %s", err)
}
if err != nil {
log := GetCRIULogErrors(checkpointDir, "dump")
err = fmt.Errorf("checkpoint failed:\n%s", log)
s.sendControl(err)
return shared.OperationError(err)
}
/*
* We do the serially right now, but there's really no reason for us
* to; since we have separate websockets, we can do it in parallel if
* we wanted to. However, assuming we're network bound, there's really
* no reason to do these in parallel. In the future when we're using
* p.haul's protocol, it will make sense to do these in parallel.
*/
if err := RsyncSend(shared.AddSlash(checkpointDir), s.criuConn); err != nil {
s.sendControl(err)
return shared.OperationError(err)
}
}
fsDir := s.container.ConfigItem("lxc.rootfs")[0]
if err := RsyncSend(shared.AddSlash(fsDir), s.fsConn); err != nil {
s.sendControl(err)
return shared.OperationError(err)
}
msg := MigrationControl{}
if err := s.recv(&msg); err != nil {
//.........这里部分代码省略.........
开发者ID:jumpstarter-io,项目名称:lxd,代码行数:101,代码来源:migrate.go
示例9: validateStep
func (self *specValidator) validateStep(step *parser.Step) *stepValidationError {
message := &gauge_messages.Message{MessageType: gauge_messages.Message_StepValidateRequest.Enum(),
StepValidateRequest: &gauge_messages.StepValidateRequest{StepText: proto.String(step.Value), NumberOfParameters: proto.Int(len(step.Args))}}
response, err := conn.GetResponseForMessageWithTimeout(message, self.runner.Connection, config.RunnerRequestTimeout())
if err != nil {
return &stepValidationError{step: step, message: err.Error(), fileName: self.specification.FileName}
}
if response.GetMessageType() == gauge_messages.Message_StepValidateResponse {
validateResponse := response.GetStepValidateResponse()
if !validateResponse.GetIsValid() {
return &stepValidationError{step: step, fileName: self.specification.FileName, errorType: validateResponse.ErrorType, message: *validateResponse.ErrorMessage}
}
return nil
} else {
return &stepValidationError{step: step, fileName: self.specification.FileName, errorType: &invalidResponse, message: "Invalid response from runner for Validation request"}
}
}
开发者ID:magictests,项目名称:gauge,代码行数:17,代码来源:validator.go
示例10: Do
func (s *migrationSourceWs) Do(migrateOp *operation) error {
<-s.allConnected
criuType := CRIUType_CRIU_RSYNC.Enum()
if !s.live {
criuType = nil
err := s.container.StorageStart()
if err != nil {
return err
}
defer s.container.StorageStop()
}
idmaps := make([]*IDMapType, 0)
idmapset := s.container.IdmapSet()
if idmapset != nil {
for _, ctnIdmap := range idmapset.Idmap {
idmap := IDMapType{
Isuid: proto.Bool(ctnIdmap.Isuid),
Isgid: proto.Bool(ctnIdmap.Isgid),
Hostid: proto.Int(ctnIdmap.Hostid),
Nsid: proto.Int(ctnIdmap.Nsid),
Maprange: proto.Int(ctnIdmap.Maprange),
}
idmaps = append(idmaps, &idmap)
}
}
driver, fsErr := s.container.Storage().MigrationSource(s.container)
/* the protocol says we have to send a header no matter what, so let's
* do that, but then immediately send an error.
*/
snapshots := []*Snapshot{}
snapshotNames := []string{}
if fsErr == nil {
fullSnaps := driver.Snapshots()
for _, snap := range fullSnaps {
snapshots = append(snapshots, snapshotToProtobuf(snap))
snapshotNames = append(snapshotNames, shared.ExtractSnapshotName(snap.Name()))
}
}
myType := s.container.Storage().MigrationType()
header := MigrationHeader{
Fs: &myType,
Criu: criuType,
Idmap: idmaps,
SnapshotNames: snapshotNames,
Snapshots: snapshots,
}
if err := s.send(&header); err != nil {
s.sendControl(err)
return err
}
if fsErr != nil {
s.sendControl(fsErr)
return fsErr
}
if err := s.recv(&header); err != nil {
s.sendControl(err)
return err
}
if *header.Fs != myType {
myType = MigrationFSType_RSYNC
header.Fs = &myType
driver, _ = rsyncMigrationSource(s.container)
}
// All failure paths need to do a few things to correctly handle errors before returning.
// Unfortunately, handling errors is not well-suited to defer as the code depends on the
// status of driver and the error value. The error value is especially tricky due to the
// common case of creating a new err variable (intentional or not) due to scoping and use
// of ":=". Capturing err in a closure for use in defer would be fragile, which defeats
// the purpose of using defer. An abort function reduces the odds of mishandling errors
// without introducing the fragility of closing on err.
abort := func(err error) error {
driver.Cleanup()
s.sendControl(err)
return err
}
if err := driver.SendWhileRunning(s.fsConn, migrateOp); err != nil {
return abort(err)
}
restoreSuccess := make(chan bool, 1)
dumpSuccess := make(chan error, 1)
if s.live {
if header.Criu == nil {
return abort(fmt.Errorf("Got no CRIU socket type for live migration"))
} else if *header.Criu != CRIUType_CRIU_RSYNC {
//.........这里部分代码省略.........
开发者ID:akshaykarle,项目名称:lxd,代码行数:101,代码来源:migrate.go
示例11: Do
func (s *migrationSourceWs) Do(op *operation) error {
<-s.allConnected
criuType := CRIUType_CRIU_RSYNC.Enum()
if !s.live {
criuType = nil
err := s.container.StorageStart()
if err != nil {
return err
}
defer s.container.StorageStop()
}
idmaps := make([]*IDMapType, 0)
idmapset := s.container.IdmapSet()
if idmapset != nil {
for _, ctnIdmap := range idmapset.Idmap {
idmap := IDMapType{
Isuid: proto.Bool(ctnIdmap.Isuid),
Isgid: proto.Bool(ctnIdmap.Isgid),
Hostid: proto.Int(ctnIdmap.Hostid),
Nsid: proto.Int(ctnIdmap.Nsid),
Maprange: proto.Int(ctnIdmap.Maprange),
}
idmaps = append(idmaps, &idmap)
}
}
driver, fsErr := s.container.Storage().MigrationSource(s.container)
/* the protocol says we have to send a header no matter what, so let's
* do that, but then immediately send an error.
*/
snapshots := []string{}
if fsErr == nil {
fullSnaps := driver.Snapshots()
for _, snap := range fullSnaps {
snapshots = append(snapshots, shared.ExtractSnapshotName(snap.Name()))
}
}
myType := s.container.Storage().MigrationType()
header := MigrationHeader{
Fs: &myType,
Criu: criuType,
Idmap: idmaps,
Snapshots: snapshots,
}
if err := s.send(&header); err != nil {
s.sendControl(err)
return err
}
if fsErr != nil {
s.sendControl(fsErr)
return fsErr
}
if err := s.recv(&header); err != nil {
s.sendControl(err)
return err
}
if *header.Fs != myType {
myType = MigrationFSType_RSYNC
header.Fs = &myType
driver, _ = rsyncMigrationSource(s.container)
}
defer driver.Cleanup()
if err := driver.SendWhileRunning(s.fsConn); err != nil {
s.sendControl(err)
return err
}
if s.live {
if header.Criu == nil {
err := fmt.Errorf("Got no CRIU socket type for live migration")
s.sendControl(err)
return err
} else if *header.Criu != CRIUType_CRIU_RSYNC {
err := fmt.Errorf("Formats other than criu rsync not understood")
s.sendControl(err)
return err
}
checkpointDir, err := ioutil.TempDir("", "lxd_checkpoint_")
if err != nil {
s.sendControl(err)
return err
}
defer os.RemoveAll(checkpointDir)
opts := lxc.CheckpointOptions{Stop: true, Directory: checkpointDir, Verbose: true}
//.........这里部分代码省略.........
开发者ID:jameinel,项目名称:lxd,代码行数:101,代码来源:migrate.go
示例12: Analyze
// Analyze runs android lint on all Android projects that are implicitly
// referenced by the list of files on the depot path. In case of an error, it
// returns partial results.
func (ala Analyzer) Analyze(ctx *ctxpb.ShipshapeContext) ([]*notepb.Note, error) {
var notes []*notepb.Note
// Get the list of Android Projects
projects := getAndroidProjects(ctx.FilePath)
for prj := range projects {
tempReport, err := ioutil.TempFile("", report)
if err != nil {
return notes, fmt.Errorf("Could not create temp report file %s: %v", report, err)
}
defer os.Remove(tempReport.Name())
// TODO(ciera): Add project options (--classpath) when we have build information.
// TODO(clconway): The path to the binary should be configurable, especially since
// the "lint" command name is overloaded.
cmd := exec.Command(lintBin,
"--showall",
"--quiet",
"--exitcode",
"--xml", tempReport.Name(),
prj)
out, err := cmd.CombinedOutput()
log.Printf("lint output is %q", out)
switch err := err.(type) {
case nil:
// no issues. Do nothing.
case *exec.ExitError:
if err.Error() != exitStatus {
return notes, fmt.Errorf("Unexpected error code from android lint: %v", err)
}
// Get the results from xml
data, xmlErr := ioutil.ReadFile(tempReport.Name())
if xmlErr != nil {
return notes, fmt.Errorf("could not read %s : %v", tempReport.Name(), xmlErr)
}
var issues IssuesList
xmlErr = xml.Unmarshal(data, &issues)
if xmlErr != nil {
return notes, fmt.Errorf("could not unmarshal XML from %s: %v", tempReport.Name(), xmlErr)
}
// Create a bunch of notes to return, one per line from the output.
for _, issue := range issues.Issues {
notes = append(notes, ¬epb.Note{
Category: proto.String(ala.Category()),
Subcategory: proto.String(issue.Subcategory),
Description: proto.String(issue.Message),
Location: ¬epb.Location{
SourceContext: ctx.SourceContext,
Path: proto.String(filepath.Join(prj, issue.Location.File)),
Range: &rangepb.TextRange{
StartLine: proto.Int(issue.Location.Line),
StartColumn: proto.Int(issue.Location.Column),
},
},
})
}
case *exec.Error:
return notes, err
default:
return notes, err
}
}
return notes, nil
}
开发者ID:linearregression,项目名称:shipshape,代码行数:74,代码来源:analyzer.go
示例13: createConceptInfos
func (specInfoGatherer *SpecInfoGatherer) createConceptInfos() []*gauge_messages.ConceptInfo {
conceptInfos := make([]*gauge_messages.ConceptInfo, 0)
for _, concept := range specInfoGatherer.getDictionary().ConceptsMap {
stepValue := parser.CreateStepValue(concept.ConceptStep)
conceptInfos = append(conceptInfos, &gauge_messages.ConceptInfo{StepValue: parser.ConvertToProtoStepValue(&stepValue), Filepath: proto.String(concept.FileName), LineNumber: proto.Int(concept.ConceptStep.LineNo)})
}
return conceptInfos
}
开发者ID:christophermoura,项目名称:gauge,代码行数:8,代码来源:specDetails.go
示例14: genField
func genField(f *ast.Field) (*pb.FieldDescriptorProto, *pb.DescriptorProto, error) {
fdp := &pb.FieldDescriptorProto{
Name: proto.String(f.Name),
Number: proto.Int32(int32(f.Tag)),
}
switch {
case f.Required:
fdp.Label = pb.FieldDescriptorProto_LABEL_REQUIRED.Enum()
case f.Repeated:
fdp.Label = pb.FieldDescriptorProto_LABEL_REPEATED.Enum()
default:
// default is optional
fdp.Label = pb.FieldDescriptorProto_LABEL_OPTIONAL.Enum()
}
if f.KeyTypeName != "" {
mname := camelCase(f.Name) + "Entry"
vmsg := &ast.Message{
Name: mname,
Fields: []*ast.Field{
{
TypeName: f.KeyTypeName,
Type: f.KeyType,
Name: "key",
Tag: 1,
},
{
TypeName: f.TypeName,
Type: f.Type,
Name: "value",
Tag: 2,
},
},
Up: f.Up,
}
vmsg.Fields[0].Up = vmsg
vmsg.Fields[1].Up = vmsg
xdp, err := genMessage(vmsg)
if err != nil {
return nil, nil, fmt.Errorf("internal error: %v", err)
}
xdp.Options = &pb.MessageOptions{
MapEntry: proto.Bool(true),
}
fdp.Type = pb.FieldDescriptorProto_TYPE_MESSAGE.Enum()
fdp.TypeName = proto.String(qualifiedName(vmsg))
return fdp, xdp, nil
}
switch t := f.Type.(type) {
case ast.FieldType:
pt, ok := fieldTypeMap[t]
if !ok {
return nil, nil, fmt.Errorf("internal error: no mapping from ast.FieldType %v", t)
}
fdp.Type = pt.Enum()
case *ast.Message:
if !t.Group {
fdp.Type = pb.FieldDescriptorProto_TYPE_MESSAGE.Enum()
} else {
fdp.Type = pb.FieldDescriptorProto_TYPE_GROUP.Enum()
// The field name is lowercased by protoc.
*fdp.Name = strings.ToLower(*fdp.Name)
}
fdp.TypeName = proto.String(qualifiedName(t))
case *ast.Enum:
fdp.Type = pb.FieldDescriptorProto_TYPE_ENUM.Enum()
fdp.TypeName = proto.String(qualifiedName(t))
default:
return nil, nil, fmt.Errorf("internal error: bad ast.Field.Type type %T", f.Type)
}
if ext, ok := f.Up.(*ast.Extension); ok {
fdp.Extendee = proto.String(qualifiedName(ext.ExtendeeType))
}
if f.HasDefault {
fdp.DefaultValue = proto.String(f.Default)
}
if f.Oneof != nil {
n := 0
for _, oo := range f.Oneof.Up.Oneofs {
if oo == f.Oneof {
break
}
n++
}
fdp.OneofIndex = proto.Int(n)
}
return fdp, nil, nil
}
开发者ID:myitcv,项目名称:old_protobuf,代码行数:88,代码来源:gendesc.go
示例15: GetConceptInfos
func (s *SpecInfoGatherer) GetConceptInfos() []*gauge_messages.ConceptInfo {
s.waitGroup.Wait()
conceptInfos := make([]*gauge_messages.ConceptInfo, 0)
s.mutex.Lock()
for _, conceptList := range s.conceptsCache {
for _, concept := range conceptList {
stepValue := parser.CreateStepValue(concept.ConceptStep)
conceptInfos = append(conceptInfos, &gauge_messages.ConceptInfo{StepValue: gauge.ConvertToProtoStepValue(&stepValue), Filepath: proto.String(concept.FileName), LineNumber: proto.Int(concept.ConceptStep.LineNo)})
}
}
s.mutex.Unlock()
return conceptInfos
}
开发者ID:0-T-0,项目名称:gauge,代码行数:14,代码来源:specDetails.go
示例16: Do
func (s *migrationSourceWs) Do(op *operation) error {
<-s.allConnected
criuType := CRIUType_CRIU_RSYNC.Enum()
if !s.live {
criuType = nil
defer s.container.StorageStop()
}
idmaps := make([]*IDMapType, 0)
idmapset := s.container.IdmapSet()
if idmapset != nil {
for _, ctnIdmap := range idmapset.Idmap {
idmap := IDMapType{
Isuid: proto.Bool(ctnIdmap.Isuid),
Isgid: proto.Bool(ctnIdmap.Isgid),
Hostid: proto.Int(ctnIdmap.Hostid),
Nsid: proto.Int(ctnIdmap.Nsid),
Maprange: proto.Int(ctnIdmap.Maprange),
}
idmaps = append(idmaps, &idmap)
}
}
sources, fsErr := s.container.Storage().MigrationSource(s.container)
/* the protocol says we have to send a header no matter what, so let's
* do that, but then immediately send an error.
*/
snapshots := []string{}
if fsErr == nil {
/* A bit of a special case here: doing lxc launch
* host2:c1/snap1 host1:container we're sending a snapshot, but
* it ends up as the container on the other end. So, we want to
* send it as the main container (i.e. ignore its IsSnapshot()).
*/
if len(sources) > 1 {
for _, snap := range sources {
if !snap.IsSnapshot() {
continue
}
name := shared.ExtractSnapshotName(snap.Name())
snapshots = append(snapshots, name)
}
}
}
myType := s.container.Storage().MigrationType()
header := MigrationHeader{
Fs: &myType,
Criu: criuType,
Idmap: idmaps,
Snapshots: snapshots,
}
if err := s.send(&header); err != nil {
s.sendControl(err)
return err
}
if fsErr != nil {
s.sendControl(fsErr)
return fsErr
}
if err := s.recv(&header); err != nil {
s.sendControl(err)
return err
}
// TODO: actually fall back on rsync.
if *header.Fs != myType {
err := fmt.Errorf("mismatched storage types not supported yet")
s.sendControl(err)
return err
}
if s.live {
if header.Criu == nil {
err := fmt.Errorf("Got no CRIU socket type for live migration")
s.sendControl(err)
return err
} else if *header.Criu != CRIUType_CRIU_RSYNC {
err := fmt.Errorf("Formats other than criu rsync not understood")
s.sendControl(err)
return err
}
checkpointDir, err := ioutil.TempDir("", "lxd_checkpoint_")
if err != nil {
s.sendControl(err)
return err
}
defer os.RemoveAll(checkpointDir)
opts := lxc.CheckpointOptions{Stop: true, Directory: checkpointDir, Verbose: true}
err = s.container.Checkpoint(opts)
if err2 := CollectCRIULogFile(s.container, checkpointDir, "migration", "dump"); err2 != nil {
//.........这里部分代码省略.........
开发者ID:czl349095941,项目名称:lxd,代码行数:101,代码来源:migrate.go
示例17: newPhoneNumber
func newPhoneNumber(cc int, natNum uint64) *PhoneNumber {
p := &PhoneNumber{}
p.CountryCode = proto.Int(cc)
p.NationalNumber = proto.Uint64(natNum)
return p
}
开发者ID:steeve,项目名称:libphonenumber,代码行数:6,代码来源:phonenumberutil_test.go
示例18: validateStep
func (self *specValidator) validateStep(step *step) {
message := &gauge_messages.Message{MessageType: gauge_messages.Message_StepValidateRequest.Enum(),
StepValidateRequest: &gauge_messages.StepValidateRequest{StepText: proto.String(step.value), NumberOfParameters: proto.Int(len(step.args))}}
response, err := conn.GetResponseForMessageWithTimeout(message, self.runner.connection, config.RunnerRequestTimeout())
if err != nil {
self.stepValidationErrors = append(self.stepValidationErrors, &stepValidationError{step: step, message: err.Error(), fileName: self.specification.fileName})
return
}
if response.GetMessageType() == gauge_messages.Message_StepValidateResponse {
validateResponse := response.GetStepValidateResponse()
if !validateResponse.GetIsValid() {
self.stepValidationErrors = append(self.stepValidationErrors, &stepValidationError{step: step, message: validateResponse.GetErrorMessage(), fileName: self.specification.fileName})
}
} else {
self.stepValidationErrors = append(self.stepValidationErrors, &stepValidationError{step: step, message: "Invalid response from runner for Validation request", fileName: self.specification.fileName})
}
}
开发者ID:Jayasagar,项目名称:gauge,代码行数:17,代码来源:validator.go
示例19: validateStep
func (v *specValidator) validateStep(s *gauge.Step) *StepValidationError {
m := &gauge_messages.Message{MessageType: gauge_messages.Message_StepValidateRequest.Enum(),
StepValidateRequest: &gauge_messages.StepValidateRequest{StepText: proto.String(s.Value), NumberOfParameters: proto.Int(len(s.Args))}}
r, err := conn.GetResponseForMessageWithTimeout(m, v.runner.Connection, config.RunnerRequestTimeout())
if err != nil {
return NewValidationError(s, err.Error(), v.specification.FileName, nil)
}
if r.GetMessageType() == gauge_messages.Message_StepValidateResponse {
res := r.GetStepValidateResponse()
if !res.GetIsValid() {
msg := getMessage(res.ErrorType.String())
return NewValidationError(s, msg, v.specification.FileName, res.ErrorType)
}
return nil
}
return NewValidationError(s, "Invalid response from runner for Validation request", v.specification.FileName, &invalidResponse)
}
开发者ID:mattdotmatt,项目名称:gauge,代码行数:17,代码来源:validate.go
示例20: createParameterPositions
func (agent *rephraseRefactorer) createParameterPositions(orderMap map[int]int) []*gauge_messages.ParameterPosition {
paramPositions := make([]*gauge_messages.ParameterPosition, 0)
for k, v := range orderMap {
paramPositions = append(paramPositions, &gauge_messages.ParameterPosition{NewPosition: proto.Int(k), OldPosition: proto.Int(v)})
}
return paramPositions
}
开发者ID:Jayasagar,项目名称:gauge,代码行数:7,代码来源:refactor.go
注:本文中的github.com/golang/protobuf/proto.Int函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论