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


Golang thrift.NewTBinaryProtocolFactoryDefault函數代碼示例

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


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

示例1: GuessProtoFactory

func GuessProtoFactory(what string) (res thrift.TProtocolFactory) {
	switch what {
	case "compact":
		res = thrift.NewTCompactProtocolFactory()
	case "simplejson":
		res = thrift.NewTSimpleJSONProtocolFactory()
	case "json":
		res = thrift.NewTJSONProtocolFactory()
	case "binary", "":
		res = thrift.NewTBinaryProtocolFactoryDefault()
	default:
		res = thrift.NewTBinaryProtocolFactoryDefault()
	}
	return
}
開發者ID:godeep,項目名稱:goth,代碼行數:15,代碼來源:guess.go

示例2: GetTOptions

// Get clone of default Thrift client options or just return first
// given. This logic is little funny. But very convenient for per-client
// options.
func GetTOptions(options ...*TOptions) (res *TOptions) {
	if len(options) > 0 {
		return options[0]
	}
	if defaultTOptions == nil {
		defaultTOptions = &TOptions{
			DiscoveryBase: ".thrift",
			DiscoveryEnv:  "",
			TransportFactory: thrift.NewTFramedTransportFactory(
				thrift.NewTTransportFactory()),
			DialTimeout:  time.Minute * 3,
			PoolCapacity: 32,
			PoolMax:      256,
			PoolTTL:      time.Hour,
			ProtoFactory: func() thrift.TProtocolFactory {
				return thrift.NewTBinaryProtocolFactoryDefault()
			},
			Ctx:        context.Background(),
			HubFactory: DefaultTTransportHub,
		}
	}
	clone := *defaultTOptions
	res = &clone
	return
}
開發者ID:godeep,項目名稱:goth,代碼行數:28,代碼來源:options.go

示例3: Start

func (s *ThriftServer) Start() (err error) {
	processor := wire.NewBarProcessor(s.Handler)

	var transport t_thrift.TServerTransport
	if transport, err = t_thrift.NewTServerSocket(s.options.Bind); err != nil {
		return
	}
	protoFactory := t_thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := t_thrift.NewTBufferedTransportFactory(
		s.BufferSize)
	s.TServer = t_thrift.NewTSimpleServer4(processor, transport,
		transportFactory, protoFactory)

	logx.Debugf("thrift listening at %s", s.options.Info.RPCEndpoints[0])

	errChan := make(chan error, 1)
	go func() {
		errChan <- s.TServer.Serve()

	}()
	defer s.TServer.Stop()
	defer s.cancel()

	select {
	case <-s.ctx.Done():
		return
	case err = <-errChan:
		return
	}
	return
}
開發者ID:pombredanne,項目名稱:bar,代碼行數:31,代碼來源:thrift.go

示例4: Start

// Start starts an Apache Thrift server on port 8088
func Start() {
	// We expose the following endpoints:
	// /thrift/ThriftTest:
	//   Thrift service using TBinaryProtocol
	// /thrift/SecondService
	//   Thrift service using TBinaryProtocol
	// /thrift/mutliplexed
	//   Thrift service using TBinaryProtocol with TMultiplexedProtocol,
	//   serving both, ThriftTest and SecondService

	pfactory := thrift.NewTBinaryProtocolFactoryDefault()

	thriftTest := gauntlet_apache.NewThriftTestProcessor(thriftTestHandler{})
	secondService := gauntlet_apache.NewSecondServiceProcessor(secondServiceHandler{})

	multiplexed := thrift.NewTMultiplexedProcessor()
	multiplexed.RegisterProcessor("ThriftTest", thriftTest)
	multiplexed.RegisterProcessor("SecondService", secondService)

	mux := http.NewServeMux()
	mux.HandleFunc("/thrift/ThriftTest", thrift.NewThriftHandlerFunc(thriftTest, pfactory, pfactory))
	mux.HandleFunc("/thrift/SecondService", thrift.NewThriftHandlerFunc(secondService, pfactory, pfactory))
	mux.HandleFunc("/thrift/multiplexed", thrift.NewThriftHandlerFunc(multiplexed, pfactory, pfactory))

	server = net.NewHTTPServer(&http.Server{
		Addr:         addr,
		Handler:      mux,
		ReadTimeout:  5 * time.Second,
		WriteTimeout: 5 * time.Second,
	})

	if err := server.ListenAndServe(); err != nil {
		log.Fatalf("failed to start Apache Thrift server: %v", err)
	}
}
開發者ID:yarpc,項目名稱:yarpc-go,代碼行數:36,代碼來源:server.go

示例5: Test_Proto_Thrift

func Test_Proto_Thrift(t *testing.T) {
	t.Skip()
	server := &TServer{}
	err := server.Start(thrift.NewTTransportFactory())
	assert.NoError(t, err)
	defer server.Server.Stop()

	var transport thrift.TTransport
	transport, err = thrift.NewTSocket(fmt.Sprintf("127.0.0.1:%d", server.Port))
	assert.NoError(t, err)

	transportFactory := thrift.NewTTransportFactory()
	transport = transportFactory.GetTransport(transport)

	err = transport.Open()
	assert.NoError(t, err)
	defer transport.Close()

	protoFactory := thrift.NewTBinaryProtocolFactoryDefault()
	client := srv.NewTSrvClientFactory(transport, protoFactory)

	req := srv.TestRep{
		ID:   "test",
		Data: []byte("mama myla ramy"),
	}
	res, err := client.Test(&req)
	assert.NoError(t, err)
	assert.EqualValues(t, req, *res)
}
開發者ID:pombredanne,項目名稱:bar,代碼行數:29,代碼來源:t10_test.go

示例6: New

// New returns a stateful factory for Sum and Concat Endpoints
func New(protocol string, bufferSize int, framed bool, logger log.Logger) client {
	var protocolFactory thrift.TProtocolFactory
	switch protocol {
	case "compact":
		protocolFactory = thrift.NewTCompactProtocolFactory()
	case "simplejson":
		protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
	case "json":
		protocolFactory = thrift.NewTJSONProtocolFactory()
	case "binary", "":
		protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
	default:
		panic("invalid protocol")
	}

	var transportFactory thrift.TTransportFactory
	if bufferSize > 0 {
		transportFactory = thrift.NewTBufferedTransportFactory(bufferSize)
	} else {
		transportFactory = thrift.NewTTransportFactory()
	}
	if framed {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	return client{transportFactory, protocolFactory, logger}
}
開發者ID:qband,項目名稱:down,代碼行數:28,代碼來源:client.go

示例7: NewThriftServer

// New thrift server with defaults and common
func NewThriftServer(processor thrift.TProcessor) (res *TServer) {
	res = &TServer{
		ProtoFactory:     thrift.NewTBinaryProtocolFactoryDefault(),
		TransportFactory: thrift.NewTTransportFactory(),
		Processor:        processor,
	}
	return
}
開發者ID:godeep,項目名稱:goth,代碼行數:9,代碼來源:thrift.go

示例8: NewTPool

func NewTPool(endpoints []string, bufferSize int, n int, ttl time.Duration) (res *TPool) {
	res = &TPool{
		endpoints:        endpoints,
		endpointsCap:     len(endpoints) - 1,
		ttl:              ttl,
		transportFactory: thrift.NewTBufferedTransportFactory(bufferSize),
		protoFactory:     thrift.NewTBinaryProtocolFactoryDefault(),
	}
	res.ResourcePool = pools.NewResourcePool(res.factory, n, n, ttl)
	return
}
開發者ID:pombredanne,項目名稱:bar,代碼行數:11,代碼來源:tpool.go

示例9: main

func main() {

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

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

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

	bs_req := new(ui2bs.BSRequest)
	bs_req.Searchid = "123"
	bs_req.Media = new(ui2bs.Media)
	bs_req.Media.Appsid = "123"
	bs_req.Media.ChannelId = "123"
	bs_req.Adslot = new(ui2bs.AdSlot)
	bs_req.Device = new(ui2bs.Device)
	bs_req.Device.Os = ui2bs.OSType_ANDROID
	bs_resp := new(ui2bs.BSResponse)
	//	bs_resp.Ads = new([]ui2bs.Ad)
	bs_resp, err = client.Search(bs_req)
	if err != nil {
		fmt.Println("error occuse")
		fmt.Println(err)
	}
	//	for i:=0; i < 10; i++ {
	//		err := client.Search2()
	//		if err != nil {
	//			fmt.Println("serach fail")
	//			transport, err = thrift.NewTSocket(net.JoinHostPort("127.0.0.1", "8084"))
	//			transport.Open()
	//			useTransport = transportFactory.GetTransport(transport)
	//			client = bs.NewBSServiceClientFactory(useTransport, protocolFactory)
	//		}
	//		time.Sleep(1*time.Second)
	//	}
	//
	fmt.Println(bs_resp)
	fmt.Println("I am exit ")

}
開發者ID:ifzz,項目名稱:seller_adptor,代碼行數:50,代碼來源:client_stub.go

示例10: main

func main() {

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

	serverTransport, err := thrift.NewTServerSocket(NetworkAddr)
	if err != nil {
		fmt.Println("new socket fail")
	}
	handler := &BsServiceImpl{}
	processor := bs.NewBSServiceProcessor(handler)

	server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
	fmt.Println("server start")
	server.Serve()

}
開發者ID:ifzz,項目名稱:seller_adptor,代碼行數:17,代碼來源:bs_stub.go

示例11: Start

func (s *TServer) Start(transportFactory thrift.TTransportFactory) (err error) {
	if s.Port, err = fixtures.GetOpenPort(); err != nil {
		return
	}

	protoFactory := thrift.NewTBinaryProtocolFactoryDefault()
	processor := srv.NewTSrvProcessor(&service{})

	var transport thrift.TServerTransport
	if transport, err = thrift.NewTServerSocket(fmt.Sprintf(":%d", s.Port)); err != nil {
		return
	}
	s.Server = thrift.NewTSimpleServer4(processor, transport,
		transportFactory, protoFactory)
	go s.Server.Serve()
	time.Sleep(time.Millisecond * 100)
	return
}
開發者ID:pombredanne,項目名稱:bar,代碼行數:18,代碼來源:t10_test.go

示例12: newScribeServer

func newScribeServer(t *testing.T) *scribeServer {
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())

	var port int
	var transport *thrift.TServerSocket
	var err error
	for i := 0; i < 10; i++ {
		port = 10000 + rand.Intn(10000)
		transport, err = thrift.NewTServerSocket(fmt.Sprintf(":%d", port))
		if err != nil {
			t.Logf("port %d: %v", port, err)
			continue
		}
		break
	}
	if err != nil {
		t.Fatal(err)
	}

	handler := newScribeHandler(t)
	server := thrift.NewTSimpleServer4(
		scribe.NewScribeProcessor(handler),
		transport,
		transportFactory,
		protocolFactory,
	)

	go server.Serve()

	deadline := time.Now().Add(time.Second)
	for !canConnect(port) {
		if time.Now().After(deadline) {
			t.Fatal("server never started")
		}
		time.Sleep(time.Millisecond)
	}

	return &scribeServer{
		transport: transport,
		address:   fmt.Sprintf("127.0.0.1:%d", port),
		handler:   handler,
	}
}
開發者ID:jllopis,項目名稱:kit,代碼行數:44,代碼來源:collector_test.go

示例13: main

func main() {
	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 := account.NewAccountClientFactory(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()

	// 第一個請求,登錄賬號
	request := &account.Request{
		Name:     "super",
		Password: "123",
		Op:       account.Operation_LOGIN,
	}

	r, err := client.DoAction(request)
	fmt.Println(r)

	// 第二個請求,注冊賬號
	request.Op = account.Operation_REGISTER
	r, err = client.DoAction(request)
	fmt.Println(r)

	// 第三個請求,name為空的請求
	request.Name = ""
	r, err = client.DoAction(request)
	fmt.Println(r)

}
開發者ID:LC2010,項目名稱:thrift-step-by-step-go,代碼行數:39,代碼來源:account_client.go

示例14: Benchmark_Proto_Thrift_Buffered

func Benchmark_Proto_Thrift_Buffered(b *testing.B) {
	b.Skip()
	server := &TServer{}
	err := server.Start(thrift.NewTBufferedTransportFactory(thrift_buffer))
	assert.NoError(b, err)
	defer server.Server.Stop()

	var transport thrift.TTransport
	transport, err = thrift.NewTSocket(fmt.Sprintf("127.0.0.1:%d", server.Port))
	assert.NoError(b, err)

	transportFactory := thrift.NewTBufferedTransportFactory(thrift_buffer)
	transport = transportFactory.GetTransport(transport)

	err = transport.Open()
	assert.NoError(b, err)
	defer transport.Close()

	protoFactory := thrift.NewTBinaryProtocolFactoryDefault()
	client := srv.NewTSrvClientFactory(transport, protoFactory)

	b.Log(server.Port, b.N)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		b.StartTimer()
		req := srv.TestRep{
			ID:   fmt.Sprintf("%d", i),
			Data: []byte("mama myla ramy"),
		}
		res, err := client.Test(&req)
		b.StopTimer()
		assert.NoError(b, err)
		assert.EqualValues(b, req, *res)
		b.SetBytes(int64(len(req.Data) * 2))
	}
}
開發者ID:pombredanne,項目名稱:bar,代碼行數:37,代碼來源:t10_test.go

示例15: main

func main() {
	flag.Usage = Usage
	var host string
	var port int
	var protocol string
	var urlString string
	var framed bool
	var useHttp bool
	var parsedUrl url.URL
	var trans thrift.TTransport
	_ = strconv.Atoi
	_ = math.Abs
	flag.Usage = Usage
	flag.StringVar(&host, "h", "localhost", "Specify host and port")
	flag.IntVar(&port, "p", 9090, "Specify port")
	flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)")
	flag.StringVar(&urlString, "u", "", "Specify the url")
	flag.BoolVar(&framed, "framed", false, "Use framed transport")
	flag.BoolVar(&useHttp, "http", false, "Use http")
	flag.Parse()

	if len(urlString) > 0 {
		parsedUrl, err := url.Parse(urlString)
		if err != nil {
			fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
			flag.Usage()
		}
		host = parsedUrl.Host
		useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http"
	} else if useHttp {
		_, err := url.Parse(fmt.Sprint("http://", host, ":", port))
		if err != nil {
			fmt.Fprintln(os.Stderr, "Error parsing URL: ", err)
			flag.Usage()
		}
	}

	cmd := flag.Arg(0)
	var err error
	if useHttp {
		trans, err = thrift.NewTHttpClient(parsedUrl.String())
	} else {
		portStr := fmt.Sprint(port)
		if strings.Contains(host, ":") {
			host, portStr, err = net.SplitHostPort(host)
			if err != nil {
				fmt.Fprintln(os.Stderr, "error with host:", err)
				os.Exit(1)
			}
		}
		trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr))
		if err != nil {
			fmt.Fprintln(os.Stderr, "error resolving address:", err)
			os.Exit(1)
		}
		if framed {
			trans = thrift.NewTFramedTransport(trans)
		}
	}
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error creating transport", err)
		os.Exit(1)
	}
	defer trans.Close()
	var protocolFactory thrift.TProtocolFactory
	switch protocol {
	case "compact":
		protocolFactory = thrift.NewTCompactProtocolFactory()
		break
	case "simplejson":
		protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
		break
	case "json":
		protocolFactory = thrift.NewTJSONProtocolFactory()
		break
	case "binary", "":
		protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
		break
	default:
		fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol)
		Usage()
		os.Exit(1)
	}
	client := zipkinquery.NewZipkinQueryClientFactory(trans, protocolFactory)
	if err := trans.Open(); err != nil {
		fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
		os.Exit(1)
	}

	switch cmd {
	case "getTraceIds":
		if flag.NArg()-1 != 1 {
			fmt.Fprintln(os.Stderr, "GetTraceIds requires 1 args")
			flag.Usage()
		}
		arg77 := flag.Arg(1)
		mbTrans78 := thrift.NewTMemoryBufferLen(len(arg77))
		defer mbTrans78.Close()
		_, err79 := mbTrans78.WriteString(arg77)
		if err79 != nil {
//.........這裏部分代碼省略.........
開發者ID:cnicolov,項目名稱:kit,代碼行數:101,代碼來源:zipkin_query-remote.go


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