當前位置: 首頁>>代碼示例>>Golang>>正文


Golang proto.String函數代碼示例

本文整理匯總了Golang中code/google/com/p/goprotobuf/proto.String函數的典型用法代碼示例。如果您正苦於以下問題:Golang String函數的具體用法?Golang String怎麽用?Golang String使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了String函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: HandleClientJoinGroup

// 客戶端申請加入討論組
func HandleClientJoinGroup(conn *net.TCPConn, recPacket *packet.Packet) {
	// read
	readMsg := &pb.PbClientJoinGroup{}
	packet.Unpack(recPacket, readMsg)

	from_uuid := readMsg.GetFromUuid()
	group_id := readMsg.GetGroupId()
	// note_msg := readMsg.GetNoteMsg()
	// timestamp := readMsg.GetTimestamp()

	// 加入討論組
	if ret := groupinfo.JoinGroup(from_uuid, group_id); !ret {
		return
	}

	group_name, _ := groupinfo.GetGroupNameAndOwner(group_id)

	// write
	writeMsg := pb.PbServerNotifyJoinGroup{
		ApplicantUuid: proto.String(from_uuid),
		GroupId:       proto.String(group_id),
		GroupName:     proto.String(group_name),
		Timestamp:     proto.Int64(time.Now().Unix()),
	}

	// 通知所有組員,這個消息不離線存儲
	group_members := groupinfo.GetAllUuid(group_id)
	for i := 1; i < len(group_members); i++ {
		SendPbData(UuidMapConn.Get(group_members[i]).(*net.TCPConn), packet.PK_ServerNotifyJoinGroup, writeMsg)
	}
}
開發者ID:cautonwong,項目名稱:chatserver,代碼行數:32,代碼來源:group.go

示例2: TestFrameworkMessageHandling

func TestFrameworkMessageHandling(t *testing.T) {
	sched := NewMesosScheduler()
	sched.FrameworkMessage = func(schedDriver *SchedulerDriver, execId *mesos.ExecutorID, slaveId *mesos.SlaveID, data []byte) {
		if execId.GetValue() != "test-executor-1" {
			log.Fatal("Scheduler.FrameworkMessage.ExecutorId not received.")
		}

		if slaveId.GetValue() != "test-slave-1" {
			log.Fatal("Scheduler.FrameworkMessage.SlaveId not received.")
		}

		if string(data) != "Hello-Test" {
			log.Fatal("Scheduler.FrameworkMessage.Data not received.")
		}
	}

	msg := &mesos.ExecutorToFrameworkMessage{
		SlaveId:     &mesos.SlaveID{Value: proto.String("test-slave-1")},
		FrameworkId: &mesos.FrameworkID{Value: proto.String("test-framework-1")},
		ExecutorId:  &mesos.ExecutorID{Value: proto.String("test-executor-1")},
		Data:        []byte("Hello-Test"),
	}
	driver, err := NewSchedDriver(sched, &mesos.FrameworkInfo{}, "localhost:0")
	if err != nil {
		t.Fatal(err)
	}
	driver.schedMsgQ <- msg

}
開發者ID:vladimirvivien,項目名稱:gomes,代碼行數:29,代碼來源:driver_test.go

示例3: netGetClResources

// TODO: only download new resources if updated versions
func netGetClResources(e *Engine) netHandler {
	return func(msg messages.GetCLResources, conn netengine.Connection) []byte {
		appendResourceScript := func(dest []*messages.Resource, script *Script) []*messages.Resource {
			res := new(messages.Resource)
			res.Name = proto.String(script.Path)
			kind := messages.ResourceType_RType_Script
			res.Type = &kind
			res.Script = proto.String(string(script.Source))
			res.ShouldExecSCript = proto.Bool(script.ShouldExec)
			dest = append(dest, res)
			return dest
		}

		// get all resources
		resources := make([]*messages.Resource, 0)
		for _, addon := range e.Addons {
			for _, script := range addon.ClientScripts {
				resources = appendResourceScript(resources, script)
			}
		}
		response := new(messages.GetCLResourcesResp)
		response.Resources = resources
		encoded, err := netengine.EncodeMessage(response, int32(messages.MessageTypes_GETCLRESOURCESRESP))
		if err != nil {
			e.Log.Error("Error encoding GetClResources response ", err)
			return make([]byte, 0)

		}
		return encoded
	}
}
開發者ID:jonas747,項目名稱:fortia-server,代碼行數:32,代碼來源:messsagehandlers.go

示例4: read

//處理查找節點的請求
//本節點定期查詢已知節點是否在線,更新節點信息
func (this *Manager) read() {
	clientConn, _ := this.serverManager.GetController().GetSession(this.rootId.String())
	for {
		node := <-this.nodeStore.OutFindNode
		if node.NodeId != nil {
			findNodeOne := &msg.FindNodeReq{
				NodeId: proto.String(this.nodeStore.GetRootId()),
				FindId: proto.String(node.NodeId.String()),
			}
			findNodeBytes, _ := proto.Marshal(findNodeOne)
			// clientConn := this.serverManager.GetController().GetClientByName("firstConnPeer")
			// fmt.Println(clientConn)
			clientConn.Send(msg.FindNodeReqNum, &findNodeBytes)
		}
		if node.NodeIdShould != nil {
			findNodeOne := &msg.FindNodeReq{
				NodeId: proto.String(this.nodeStore.GetRootId()),
				FindId: proto.String(node.NodeIdShould.String()),
			}
			findNodeBytes, _ := proto.Marshal(findNodeOne)
			// clientConn := this.serverManager.GetController().GetClientByName("firstConnPeer")
			clientConn.Send(msg.FindNodeReqNum, &findNodeBytes)
		}
	}
}
開發者ID:cokeboL,項目名稱:mandela,代碼行數:27,代碼來源:manager.go

示例5: TestResourceOffersMessageHandling

func TestResourceOffersMessageHandling(t *testing.T) {
	sched := NewMesosScheduler()
	sched.ResourceOffers = func(driver *SchedulerDriver, offers []*mesos.Offer) {
		if len(offers) != 1 {
			log.Fatalf("Scheduler.ResourceOffers expected 1 offer, but got", len(offers))
		}
		if offers[0].GetId().GetValue() != "offer-1" {
			log.Fatalln("Scheduler.ResourceOffers exepected value not received")
		}
	}

	msg := &mesos.ResourceOffersMessage{
		Offers: []*mesos.Offer{
			&mesos.Offer{
				Id:          &mesos.OfferID{Value: proto.String("offer-1")},
				FrameworkId: &mesos.FrameworkID{Value: proto.String("test-framework-1")},
				SlaveId:     &mesos.SlaveID{Value: proto.String("test-slave-1")},
				Hostname:    proto.String("localhost"),
			},
		},
	}
	driver, err := NewSchedDriver(sched, &mesos.FrameworkInfo{}, "localhost:0")
	if err != nil {
		t.Fatal(err)
	}
	driver.schedMsgQ <- msg
}
開發者ID:vladimirvivien,項目名稱:gomes,代碼行數:27,代碼來源:driver_test.go

示例6: TestParseSectionAddressTable_Valid

func TestParseSectionAddressTable_Valid(t *testing.T) {
	lines := []string{
		"10 11",
		"MAC1 IP1",
		"MAC2 IP2",
	}
	trace := Trace{}
	err := parseSectionAddressTable(lines, &trace)
	if err != nil {
		t.Fatal("Unexpected error:", err)
	}
	expectedTrace := Trace{
		AddressTableFirstId: proto.Int32(10),
		AddressTableSize:    proto.Int32(11),
		AddressTableEntry: []*AddressTableEntry{
			&AddressTableEntry{
				MacAddress: proto.String("MAC1"),
				IpAddress:  proto.String("IP1"),
			},
			&AddressTableEntry{
				MacAddress: proto.String("MAC2"),
				IpAddress:  proto.String("IP2"),
			},
		},
	}
	checkProtosEqual(t, &expectedTrace, &trace)
}
開發者ID:sburnett,項目名稱:bismark-passive-server-go,代碼行數:27,代碼來源:trace_test.go

示例7: Parse

func (p *Parser) Parse() *tp.ScriptObject {
	script := new(tp.ScriptObject)
	// script.Name = proto.String(p.FullPath)

	if !p.RootFile || TritiumParserShowRewriterFileName {
		script.Name = proto.String(filepath.Join(p.ScriptPath, p.FileName))
	} else {
		script.Name = proto.String("__rewriter__")
	}

	stmts := tp.ListInstructions()
	defs := make([]*tp.Function, 0) // Add a new constructor in instruction.go

	// Look for the namespace directive first.
	if p.peek().Lexeme == NAMESPACE {
		p.namespaces()
	}

	for p.peek().Lexeme != EOF {
		switch p.peek().Lexeme {
		case FUNC:
			defs = append(defs, p.definition())
		case OPEN:
			p.open(false)
		default:
			stmt := p.statement()
			stmts = append(stmts, stmt)
			// need to intersperse imports with definitions
			if constants.Instruction_InstructionType_name[int32(stmt.GetType())] == "IMPORT" {
				// Make a special function stub that represents the import.
				// Need to do this because we can't mix definitions and instructions in
				// the same array.
				imp := new(tp.Function)
				imp.Name = proto.String("@import")
				imp.Description = proto.String(stmt.GetValue())
				defs = append(defs, imp)
			}
		}
	}

	if len(defs) == 0 {
		defs = nil
	}

	var line int32
	if len(stmts) == 0 {
		stmts = nil
	} else {
		line = *stmts[0].LineNumber
	}

	script.Functions = defs
	script.Root = tp.MakeBlock(stmts, line)

	// if defs == nil && p.currentNamespace() != "tritium" {
	// 	panic(fmt.Sprintf("%s: %d -- custom modules may only be declared in function definition files", p.FileName, moduleLineNum))
	// }

	return script
}
開發者ID:nmakiya,項目名稱:tritium,代碼行數:60,代碼來源:squid_parser.go

示例8: gossipTo

func (g *Gossiper) gossipTo(addr *net.TCPAddr, digests []*Digest) {
	conn, err := net.DialTCP("tcp", nil, addr)
	if err != nil {
		g.logger.Printf("gossiper gossip to %s error: %s\n", addr, err)
		return
	}

	g.mutex.Lock()
	if g.stoped {
		g.mutex.Unlock()
		conn.Close()
		return
	}

	syn := &SynMessage{
		Id:      proto.String(g.id),
		Origin:  proto.String(g.origin),
		Digests: digests,
	}

	g.mutex.Unlock()

	if err := encode(conn, syn); err != nil {
		conn.Close()
	}

	g.readMessage(conn)
}
開發者ID:hujh,項目名稱:gossip,代碼行數:28,代碼來源:gossiper.go

示例9: handleSynMessage

func (g *Gossiper) handleSynMessage(conn net.Conn, syn *SynMessage) {
	if g.origin != syn.GetOrigin() {
		conn.Close()
		return
	}

	g.mutex.Lock()
	if g.stoped {
		g.mutex.Unlock()
		conn.Close()
		return
	}

	digests, deltas := g.scuttlebutt(syn.GetId(), syn.GetDigests())

	ack := &AckMessage{
		Id:      proto.String(g.id),
		Origin:  proto.String(g.origin),
		Digests: digests,
		Deltas:  deltas,
	}

	g.mutex.Unlock()

	if err := encode(conn, ack); err != nil {
		conn.Close()
	}

	g.readMessage(conn)
}
開發者ID:hujh,項目名稱:gossip,代碼行數:30,代碼來源:gossiper.go

示例10: keyToProto

// keyToProto converts a *Key to a Reference proto.
func keyToProto(defaultAppID string, k *Key) *pb.Reference {
	appID := k.appID
	if appID == "" {
		appID = defaultAppID
	}
	n := 0
	for i := k; i != nil; i = i.parent {
		n++
	}
	e := make([]*pb.Path_Element, n)
	for i := k; i != nil; i = i.parent {
		n--
		e[n] = &pb.Path_Element{
			Type: &i.kind,
		}
		// At most one of {Name,Id} should be set.
		// Neither will be set for incomplete keys.
		if i.stringID != "" {
			e[n].Name = &i.stringID
		} else if i.intID != 0 {
			e[n].Id = &i.intID
		}
	}
	var namespace *string
	if k.namespace != "" {
		namespace = proto.String(k.namespace)
	}
	return &pb.Reference{
		App:       proto.String(appID),
		NameSpace: namespace,
		Path: &pb.Path{
			Element: e,
		},
	}
}
開發者ID:kleopatra999,項目名稱:appengine,代碼行數:36,代碼來源:datastore.go

示例11: 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) {

	protoEntries := make([]*protobuf.ProtoAppendEntriesRequest_ProtoLogEntry, len(req.Entries))

	for i, entry := range req.Entries {
		protoEntries[i] = &protobuf.ProtoAppendEntriesRequest_ProtoLogEntry{
			Index:       proto.Uint64(entry.Index),
			Term:        proto.Uint64(entry.Term),
			CommandName: proto.String(entry.CommandName),
			Command:     entry.Command,
		}
	}

	pb := &protobuf.ProtoAppendEntriesRequest{
		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:      protoEntries,
	}

	p, err := proto.Marshal(pb)
	if err != nil {
		return -1, err
	}

	return w.Write(p)
}
開發者ID:sunatthegilddotcom,項目名稱:etcd,代碼行數:31,代碼來源:append_entries_request.go

示例12: Run

func (self *ResMan) Run(master string) {
	frameworkIdStr := FRAMEWORK_ID
	frameworkId := &mesos.FrameworkID{Value: &frameworkIdStr}
	driver := mesos.SchedulerDriver{
		Master: master,
		Framework: mesos.FrameworkInfo{
			Name:            proto.String("TyrantFramework"),
			User:            proto.String(""),
			FailoverTimeout: failoverTimeout,
			Id:              frameworkId,
		},

		Scheduler: &mesos.Scheduler{
			ResourceOffers: self.OnResourceOffers,
			StatusUpdate:   self.OnStatusUpdate,
			Error:          self.OnError,
			Disconnected:   self.OnDisconnected,
			Registered:     self.OnRegister,
			Reregistered:   self.OnReregister,
		},
	}

	driver.Init()
	defer driver.Destroy()
	go self.EventLoop()

	driver.Start()
	<-self.exit
	log.Debug("exit")
	driver.Stop(false)
}
開發者ID:NextMark,項目名稱:tyrant,代碼行數:31,代碼來源:scheduler.go

示例13: testTargetManager

func testTargetManager(t test.Tester) {
	targetManager := NewTargetManager(nopIngester{}, 3)
	testJob1 := config.JobConfig{
		JobConfig: pb.JobConfig{
			Name:           proto.String("test_job1"),
			ScrapeInterval: proto.String("1m"),
		},
	}
	testJob2 := config.JobConfig{
		JobConfig: pb.JobConfig{
			Name:           proto.String("test_job2"),
			ScrapeInterval: proto.String("1m"),
		},
	}

	target1GroupA := &fakeTarget{
		schedules: []time.Time{time.Now()},
		interval:  time.Minute,
	}
	target2GroupA := &fakeTarget{
		schedules: []time.Time{time.Now()},
		interval:  time.Minute,
	}

	targetManager.AddTarget(testJob1, target1GroupA)
	targetManager.AddTarget(testJob1, target2GroupA)

	target1GroupB := &fakeTarget{
		schedules: []time.Time{time.Now()},
		interval:  time.Minute * 2,
	}

	targetManager.AddTarget(testJob2, target1GroupB)
}
開發者ID:pjjw,項目名稱:prometheus,代碼行數:34,代碼來源:targetmanager_test.go

示例14: main

func main() {
	log.Println("Starting gomestest.")
	log.Println("Assuming master 127.0.0.1:5050...")

	master := "127.0.0.1:5050"

	framework := &mesos.FrameworkInfo{
		User: proto.String("test"),
		Name: proto.String("gomes"),
		Id:   &mesos.FrameworkID{Value: proto.String("gomes-framework-1")},
	}

	log.Println("Registering framework" + framework.String())

	driver, err := gomes.NewSchedDriver(Sched, framework, master)
	if err != nil {
		log.Println("Unable to create a SchedulerDriver", err.Error())
	}

	stat := driver.Run()
	if stat != mesos.Status_DRIVER_STOPPED {
		log.Println("A problem occured, framework reported status " + stat)
	}
	driver.Stop(false)
}
開發者ID:vladimirvivien,項目名稱:gomes,代碼行數:25,代碼來源:gomestest.go

示例15: TestParseSectionIntro_Valid

func TestParseSectionIntro_Valid(t *testing.T) {
	lines := []string{
		"10",
		"BUILDID",
		"NODEID 123 321 789",
		"12 23 34",
	}
	trace := Trace{}
	err := parseSectionIntro(lines, &trace)
	if err != nil {
		t.Fatal("Unexpected error:", err)
	}
	expectedTrace := Trace{
		FileFormatVersion: proto.Int32(10),
		BuildId:           proto.String("BUILDID"),
		NodeId:            proto.String("NODEID"),
		ProcessStartTimeMicroseconds: proto.Int64(123),
		SequenceNumber:               proto.Int32(321),
		TraceCreationTimestamp:       proto.Int64(789),
		PcapReceived:                 proto.Uint32(12),
		PcapDropped:                  proto.Uint32(23),
		InterfaceDropped:             proto.Uint32(34),
	}
	checkProtosEqual(t, &expectedTrace, &trace)
}
開發者ID:sburnett,項目名稱:bismark-passive-server-go,代碼行數:25,代碼來源:trace_test.go


注:本文中的code/google/com/p/goprotobuf/proto.String函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。