当前位置: 首页>>代码示例>>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;未经允许,请勿转载。