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


Golang thrift.NewTBinaryProtocolFactoryDefault函數代碼示例

本文整理匯總了Golang中git/apache/org/thrift/git/lib/go/thrift.NewTBinaryProtocolFactoryDefault函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTBinaryProtocolFactoryDefault函數的具體用法?Golang NewTBinaryProtocolFactoryDefault怎麽用?Golang NewTBinaryProtocolFactoryDefault使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: binary

func binary() {
	fmt.Printf("\n ==== demo Thrift Binary serialization ====\n")
	t := thrift.NewTMemoryBufferLen(1024)
	p := thrift.NewTBinaryProtocolFactoryDefault().GetProtocol(t)

	tser := &thrift.TSerializer{
		Transport: t,
		Protocol:  p,
	}

	str := "hi there"
	a := &tutorial.Work{
		Num1:    12,
		Num2:    24,
		Comment: &str,
	}

	by, err := tser.Write(a)
	panicOn(err)
	fmt.Printf("by = '%v', length %v\n", string(by), len(by))

	t2 := thrift.NewTMemoryBufferLen(1024)
	p2 := thrift.NewTBinaryProtocolFactoryDefault().GetProtocol(t2)

	deser := &thrift.TDeserializer{
		Transport: t2,
		Protocol:  p2,
	}

	b := tutorial.NewWork()
	deser.Transport.Close() // resets underlying bytes.Buffer
	err = deser.Read(b, by)
	panicOn(err)
	fmt.Printf("b = '%#v'\n", b)
}
開發者ID:glycerine,項目名稱:golang-thrift-minimal-example,代碼行數:35,代碼來源:serialize.go

示例2: main

func main() {
	socket, err := thrift.NewTSocket("localhost:8090")
	if err != nil {
		fmt.Printf("There was an error creating your socket! Here it is %v", err)
		os.Exit(1)
	}
	transport := thrift.NewTBufferedTransport(socket, 1024)
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	client := service.NewMakeTagsClientFactory(transport, protocolFactory)
	pwd, _ := os.Getwd()
	fileName := pwd + "/img.png"
	fileName, _ = filepath.Abs(fileName)
	imgBytes, err := ioutil.ReadFile(fileName)
	if err != nil {
		fmt.Printf("There was an err reading the file! Here it is %v", err)
		os.Exit(1)
	}

	socket.Open()
	tags, err := client.Generate(service.Image(imgBytes))
	if err != nil {
		fmt.Printf("There was an err getting the tags! Here it is %v ", err)
		os.Exit(1)
	}
	fmt.Printf("These are the tags for your image %v", tags)
	socket.Close()
}
開發者ID:faiq,項目名稱:intro-to-rpc,代碼行數:27,代碼來源:client.go

示例3: main

func main() {
	startTime := currentTimeMillis()

	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	transport, err := thrift.NewTSocket(NETWORK_ADDR)
	if err != nil {
		logrus.Fatal(os.Stderr, "error resolving address:", err)
	}

	useTransport := transportFactory.GetTransport(transport)
	client := rpc.NewSessionManagerClientFactory(useTransport, protocolFactory)
	if err := transport.Open(); err != nil {
		logrus.Fatal(os.Stderr, "Error opening socket to "+NETWORK_ADDR, err)
	}
	defer transport.Close()

	// 開始調用服務的接口
	ctx := rpc.NewSessionContext()

	sid, _ := client.CreateSession(ctx)
	logrus.Infof("創新新的會話id => %s", sid)

	ctx, _ = client.GetSession(sid)
	logrus.Infof("獲取會話上下文 => %+v", ctx)

	endTime := currentTimeMillis()
	logrus.Infof("本次調用用時: %d 毫秒", endTime-startTime)

}
開發者ID:ypyf,項目名稱:golang-study,代碼行數:31,代碼來源:main.go

示例4: Test_Push

// go test github.com/citysir/zpush/push -test.v
func Test_Push(t *testing.T) {
	startTime := currentTimeMillis()
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	transport, err := thrift.NewTSocket("127.0.0.1:19090")
	if err != nil {
		t.Log(os.Stderr, "error resolving address:", err)
		os.Exit(1)
	}

	useTransport := transportFactory.GetTransport(transport)
	client := push.NewPushServiceClientFactory(useTransport, protocolFactory)
	if err := transport.Open(); err != nil {
		t.Log(os.Stderr, "Error opening socket to 127.0.0.1:19090", " ", err)
		os.Exit(1)
	}
	defer transport.Close()

	for i := 0; i < 1000; i++ {
		paramMap := make(map[string]string)
		paramMap["name"] = "qinerg"
		paramMap["passwd"] = "123456"
		result, err := client.FunCall(currentTimeMillis(), "login", paramMap)
		t.Log(i, "Call->", result, err)
	}

	endTime := currentTimeMillis()
	t.Log("Program exit. time->", endTime, startTime, (endTime - startTime))
}
開發者ID:citysir,項目名稱:zpush,代碼行數:31,代碼來源:main_test.go

示例5: main

func main() {
	startTime := currentTimeMillis()
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	transport, err := thrift.NewTSocket(net.JoinHostPort("127.0.0.1", "19090"))
	if err != nil {
		fmt.Fprintln(os.Stderr, "error resolving address:", err)
		os.Exit(1)
	}

	useTransport := transportFactory.GetTransport(transport)
	client := rpc.NewRpcServiceClientFactory(useTransport, protocolFactory)
	if err := transport.Open(); err != nil {
		fmt.Fprintln(os.Stderr, "Error opening socket to 127.0.0.1:19090", " ", err)
		os.Exit(1)
	}
	defer transport.Close()

	for i := 0; i < 1000; i++ {
		paramMap := make(map[string]string)
		paramMap["name"] = "qinerg"
		paramMap["passwd"] = "123456"
		r1, e1 := client.FunCall(currentTimeMillis(), "login", paramMap)
		fmt.Println(i, "Call->", r1, e1)
	}

	endTime := currentTimeMillis()
	fmt.Println("Program exit. time->", endTime, startTime, (endTime - startTime))
}
開發者ID:bonly,項目名稱:exercise,代碼行數:30,代碼來源:20120302_thrift_cli.go

示例6: main

func main() {
	var err error
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	var transport thrift.TTransport
	transport, err = thrift.NewTSocket(listen)
	if err != nil {
		fmt.Println("error, thrift init!")
		return
	}
	transport = transportFactory.GetTransport(transport)
	defer transport.Close()
	if err := transport.Open(); err != nil {
		fmt.Printf("error %v\n", err)
		return
	}
	client := puller.NewPullerClientFactory(transport, protocolFactory)
	var request puller.Request
	request.UserId = 12398
	request.Payload = "dlrow olleh"
	var response *puller.Response
	response, err = client.Pull(&request)
	if err != nil {
		fmt.Printf("error, response[%v]\n", err)
		return
	}
	fmt.Printf("response:[%v]\n", response)
}
開發者ID:visilicon,項目名稱:thrift-go,代碼行數:28,代碼來源:main.go

示例7: NewPelicanClient

// create a new PelicanClient instance for a given host
func NewPelicanClient(host string) *PelicanClient {

	// init client and catch any errors
	socket, err := thrift.NewTSocket(host)
	if err != nil {
		panic(err)
	}

	// create a transport factory
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())

	// create a binary protocal factory
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	// create a binary transport for the socket
	transport := transportFactory.GetTransport(socket)

	// create a new Pelican User service client
	client := user.NewUserSvcClientFactory(transport, protocolFactory)

	// fill our wrapper struct
	return &PelicanClient{
		Host:      host,
		Transport: transport,
		Client:    client,
	}

}
開發者ID:mdennebaum,項目名稱:narwhal,代碼行數:29,代碼來源:pelican.go

示例8: NewHbaseServer

// NewHbaseServer starts an self-implementation hbase
func NewHbaseServer(hb Hbase) (*TestServer, error) {

	port, _ := GetPort()
	addr := fmt.Sprintf(":%d", port)

	// fork a goroutine to serve requests
	var transportFactory thrift.TTransportFactory
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory = thrift.NewTBufferedTransportFactory(8192)
	transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	transport, err := thrift.NewTServerSocket(addr)
	if err != nil {
		log.Fatal(err)
	}
	srv := thrift.NewTSimpleServer4(
		NewHbaseProcessor(hb),
		transport,
		transportFactory,
		protocolFactory,
	)
	if err := srv.Listen(); err != nil {
		log.Fatal(err)
	}
	go srv.AcceptLoop()

	// TODO: stop server when stop chan is closed
	return &TestServer{
		Port: port,
		stop: make(chan struct{}),
	}, nil
}
開發者ID:csigo,項目名稱:hbase,代碼行數:32,代碼來源:inmem.go

示例9: Connect

func Connect(host string, options Options) (*Connection, error) {
	transport, err := thrift.NewTSocket(host)
	if err != nil {
		return nil, err
	}

	if err := transport.Open(); err != nil {
		return nil, err
	}

	if transport == nil {
		return nil, errors.New("nil thrift transport")
	}

	/*
		NB: hive 0.13's default is a TSaslProtocol, but
		there isn't a golang implementation in apache thrift as
		of this writing.
	*/
	protocol := thrift.NewTBinaryProtocolFactoryDefault()
	client := tcliservice.NewTCLIServiceClientFactory(transport, protocol)

	session, err := client.OpenSession(*tcliservice.NewTOpenSessionReq())
	if err != nil {
		return nil, err
	}

	return &Connection{client, session.SessionHandle, options}, nil
}
開發者ID:charithe,項目名稱:hivething,代碼行數:29,代碼來源:connection.go

示例10: createClientFactory

// create one client instance
func (zt *ZooThrift) createClientFactory() (interface{}, error) {
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	address := zt.provider.Selector()
	if address != "" {
		transport, err := thrift.NewTSocket(address)
		if err != nil {
			return nil, err
		}
		useTransport := transportFactory.GetTransport(transport)
		client := reflect.ValueOf(zt.Service)
		mutable := client.Elem()
		mutable.FieldByName("Transport").Set(reflect.Value(reflect.ValueOf(useTransport)))
		mutable.FieldByName("ProtocolFactory").Set(reflect.Value(reflect.ValueOf(protocolFactory)))
		mutable.FieldByName("InputProtocol").Set(reflect.Value(reflect.ValueOf(protocolFactory.GetProtocol(useTransport))))
		mutable.FieldByName("OutputProtocol").Set(reflect.Value(reflect.ValueOf(protocolFactory.GetProtocol(useTransport))))
		mutable.FieldByName("SeqId").SetInt(0)
		if err := transport.Open(); err != nil {
			return nil, err
		}
		return zt.Service, nil
	} else {
		return nil, ErrSerAddress
	}
}
開發者ID:nosix-me,項目名稱:zoothrift,代碼行數:26,代碼來源:zoothrift.go

示例11: SendSms

func SendSms(msgSend string, phones_slice []int64) {
	// random choice host
	hosts := []string{"10.231.144.136", "10.231.144.137"}
	rk := GenRandn(len(hosts))
	host := hosts[rk]
	port := "9090"

	transport, err := thrift.NewTSocket(net.JoinHostPort(host, port))
	if err != nil {
		fmt.Fprintln(os.Stderr, "error resolving address:", err)
		os.Exit(1)
	}
	transportFactory := thrift.NewTBufferedTransportFactory(10240)
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	useTransport := transportFactory.GetTransport(transport)
	client := sms.NewMessageServiceClientFactory(useTransport, protocolFactory)
	if err := transport.Open(); err != nil {
		fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
		os.Exit(1)
	}
	defer transport.Close()

	msg := sms.NewMessage()
	msg.Phones = phones_slice
	msg.BusinessId = 200100000
	msg.Message = msgSend
	client.SendMessage(msg)
}
開發者ID:dogeerf,項目名稱:tool,代碼行數:29,代碼來源:xmail.go

示例12: main

func main() {
	transportFactory := thrift.NewTFramedTransportFactory(
		thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	addr := "localhost:3636"

	socket, err := thrift.NewTSocket(addr)
	if err != nil {
		panic(err)
	}

	transport := transportFactory.GetTransport(socket)
	defer transport.Close()
	if err := transport.Open(); err != nil {
		panic(err)
	}

	client := hello.NewHelloClientFactory(transport, protocolFactory)
	request := hello.NewHelloRequest()
	request.Message = "world!"
	response, err := client.Hello(request)
	if err != nil {
		panic(err)
	}

	fmt.Println(response.Message)
}
開發者ID:sayden,項目名稱:thrift-minimal-example,代碼行數:27,代碼來源:client.go

示例13: clientCall

func clientCall(min int32) {
	startTime := currentTimeMillis()
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	transport, err := thrift.NewTSocket(NetworkAddr)
	for err != nil {
		transport, err = thrift.NewTSocket(NetworkAddr)
		if err != nil {
			log.Error("error resolving address:", err)
		}
		time.Sleep(1 * time.Second)
	}

	useTransport := transportFactory.GetTransport(transport)
	client := demo.NewRpcServiceClientFactory(useTransport, protocolFactory)
	if err := transport.Open(); err != nil {
		log.Error("Error opening socket to 127.0.0.1:19090", " ", err)
		return
	}
	defer transport.Close()

	for i := min; i < min+3; i++ {
		r1, e1 := client.Add(i, i+1)
		log.Trace("%d %s %v %v", i, "Call->", r1, e1)
	}

	endTime := currentTimeMillis()
	log.Trace("Program exit. time->", endTime, startTime, (endTime - startTime))
}
開發者ID:playnb,項目名稱:grasslands,代碼行數:30,代碼來源:test_thrift.go

示例14: Open

// opens a hive connection
func (conn *HiveConnection) Open() error {

	log.Println("creating new hive connection ")
	var transport thrift.TTransport
	var err error
	transport, err = thrift.NewTSocket(conn.Server)
	if err != nil {
		return err
	}
	if transport == nil {
		return errors.New("No TSocket connection?")
	}

	transport.Open()

	// NewTBinaryProtocolTransport(t TTransport) *TBinaryProtocol {
	protocolfac := thrift.NewTBinaryProtocolFactoryDefault()

	//NewThriftHiveClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol)
	conn.Client = thrifthive.NewThriftHiveClientFactory(transport, protocolfac)

	log.Printf("is open? %v", transport.IsOpen())
	name, err := conn.Client.GetName()
	log.Printf("in conn.Open, how is client? %v %v", name, err)

	if conn.Client == nil {
		log.Println("ERROR, no client")
		return errors.New("no client")
	}

	return nil
}
開發者ID:lasithasenanayake,項目名稱:v6engine-deps,代碼行數:33,代碼來源:hiveclient.go

示例15: Serve

// Serve starts service for the given Computation.
//
// Must be called from main() function of worker.
func Serve(comp Computation) error {
	bindAddr := os.Getenv(bolt.KConcordEnvKeyClientListenAddr)
	proxyAddr := os.Getenv(bolt.KConcordEnvKeyClientProxyAddr)

	// Init transport
	transport, err := thrift.NewTServerSocket(bindAddr)
	if err != nil {
		panic("failed to create server")
	}
	factory := thrift.NewTTransportFactory()
	transportF := thrift.NewTFramedTransportFactory(factory)

	protocolF := thrift.NewTBinaryProtocolFactoryDefault()

	proxy, err := newProxy(proxyAddr, comp.Metadata())
	if err != nil {
		panic("failed to initialize proxy")
	}

	service := newComputationService(comp, proxy)

	processor := bolt.NewComputationServiceProcessor(service)

	srv := thrift.NewTSimpleServer4(processor, transport, transportF, protocolF)
	return srv.Serve()
}
開發者ID:concord,項目名稱:concord-go,代碼行數:29,代碼來源:server.go


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