当前位置: 首页>>代码示例>>Golang>>正文


Golang thrift.NewTCompactProtocolFactory函数代码示例

本文整理汇总了Golang中git/apache/org/thrift/git/lib/go/thrift.NewTCompactProtocolFactory函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTCompactProtocolFactory函数的具体用法?Golang NewTCompactProtocolFactory怎么用?Golang NewTCompactProtocolFactory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewTCompactProtocolFactory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Connect

func (self *FlumeClient) Connect() {

	//创建一个物理连接
	tsocket, err := thrift.NewTSocket(net.JoinHostPort(self.host, strconv.Itoa(self.port)))

	if nil != err {
		log.Panic(err)
		os.Exit(-1)
	}

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

	//TLV 方式传输
	protocolFactory := thrift.NewTCompactProtocolFactory()

	//使用非阻塞io来传输
	self.transport = transportFactory.GetTransport(tsocket)

	self.thriftclient = flume.NewThriftSourceProtocolClientFactory(self.transport, protocolFactory)

	if err := self.transport.Open(); nil != err {
		log.Panic(err)
		os.Exit(-1)
	}

	self.status = STATUS_READY

	go self.checkAlive()
}
开发者ID:shijunbo,项目名称:flume-log-sdk,代码行数:29,代码来源:flume_client.go

示例2: Connect

func (self *FlumeClient) Connect() error {

	var tsocket *thrift.TSocket
	var err error
	//创建一个物理连接
	tsocket, err = thrift.NewTSocketTimeout(net.JoinHostPort(self.host, strconv.Itoa(self.port)), 10*time.Second)
	if nil != err {
		log.Printf("FLUME_CLIENT|CREATE TSOCKET|FAIL|%s|%s\n", self.HostPort(), err)
		return err
	}

	self.tsocket = tsocket

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

	//TLV 方式传输
	protocolFactory := thrift.NewTCompactProtocolFactory()

	//使用非阻塞io来传输
	self.transport = transportFactory.GetTransport(tsocket)

	self.thriftclient = flume.NewThriftSourceProtocolClientFactory(self.transport, protocolFactory)

	if err := self.transport.Open(); nil != err {
		log.Printf("FLUME_CLIENT|CREATE THRIFT CLIENT|FAIL|%s|%s", self.HostPort(), err)
		return err
	}

	self.status = STATUS_READY

	go self.checkAlive()

	return nil
}
开发者ID:rejoicelee,项目名称:flume-log-sdk,代码行数:34,代码来源:flume_client.go

示例3: main

func main() {
	flag.Usage = Usage
	protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)")
	transport := flag.String("transport", "binary", "Specify transport (framed, buffered, file, memory, zlib)")

	buffered := flag.String("buffered", "off", "Use buffered transport")
	framed := flag.String("framed", "off", "Use framed transport")

	addr := flag.String("addr", "localhost:9090", "Address to listen to")
	secure := flag.Bool("secure", false, "Use tls secure transport")

	conf_path := flag.String("conf", "nil", "配置文件路径")

	flag.Parse()

	if *conf_path == "nil" {
		Usage()
		os.Exit(1)
	}

	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:
		fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
		Usage()
		os.Exit(1)
	}

	var transportFactory thrift.TTransportFactory

	if *buffered == "on" {
		transportFactory = thrift.NewTBufferedTransportFactory(8192)
	} else {
		transportFactory = thrift.NewTTransportFactory()
	}

	if *framed == "on" {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	//获取配置文件的路径
	complete_path(conf_path)
	//初始化控制层
	handler.Init(*conf_path)

	if err := runServer(transportFactory, *transport, protocolFactory, *addr, *secure); err != nil {
		fmt.Println("error running server:", err)
	}

}
开发者ID:proudlily,项目名称:Auth_ser,代码行数:58,代码来源:main.go

示例4: runDummyFlumeAgent

// run a test flume agent
func runDummyFlumeAgent(t *testing.T) {
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTCompactProtocolFactory()
	transport, _ := thrift.NewTServerSocket("localhost:51515")

	handler := thriftSourceProtocolHandler{t}
	processor := flume.NewThriftSourceProtocolProcessor(handler)
	server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
	server.Serve()
}
开发者ID:ceocoder,项目名称:glumelogger,代码行数:11,代码来源:glumelogger_test.go

示例5: NewGlumeLogger

// NewGlumeLogger create a new GlumeLogger client, it requires a host, port and
// map of headers
func NewGlumeLogger(host string, port int, headers *map[string]string) *GlumeLogger {
	var trans thrift.TTransport
	trans, err := thrift.NewTSocket(net.JoinHostPort(host, strconv.Itoa(port)))
	if err != nil {
		fmt.Fprintln(os.Stderr, "error resolving address:", err)
		os.Exit(1)
	}
	trans = thrift.NewTFramedTransport(trans)
	client := flume.NewThriftSourceProtocolClientFactory(trans, thrift.NewTCompactProtocolFactory())
	return &GlumeLogger{client, headers, &sync.Mutex{}, log.New(os.Stdout, "[GlumeLogger] ", log.Ldate|log.Ltime)}
}
开发者ID:ceocoder,项目名称:glumelogger,代码行数:13,代码来源:glumelogger.go

示例6: launchRpcServe

func (this *Engine) launchRpcServe() (done chan interface{}) {
	var protocolFactory thrift.TProtocolFactory
	switch this.conf.rpc.protocol {
	case "binary":
		protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()

	case "json":
		protocolFactory = thrift.NewTJSONProtocolFactory()

	case "simplejson":
		protocolFactory = thrift.NewTSimpleJSONProtocolFactory()

	case "compact":
		protocolFactory = thrift.NewTCompactProtocolFactory()

	default:
		panic(fmt.Sprintf("Invalid protocol: %s", this.conf.rpc.protocol))
	}

	transportFactory := thrift.NewTTransportFactory()
	if this.conf.rpc.framed {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	serverTransport, err := thrift.NewTServerSocketTimeout(this.conf.rpc.listenAddr,
		this.conf.rpc.clientTimeout)
	if err != nil {
		panic(err)
	}

	this.rpcServer = thrift.NewTSimpleServer4(this.rpcProcessor,
		serverTransport, transportFactory, protocolFactory)
	log.Info("RPC server ready at %s", this.conf.rpc.listenAddr)

	done = make(chan interface{})
	go func() {
		for {
			err = this.rpcServer.Serve()
			if err != nil {
				log.Error(err)
				break
			}
		}

		done <- 1

	}()

	return done
}
开发者ID:jlyt898,项目名称:fae,代码行数:50,代码来源:rpc.go

示例7: TestRPC

func TestRPC(t *testing.T) {
	options := &DefaultTestOptions
	options.Port = port
	server := RunServer(options)
	if server == nil {
		t.Fatal("Failed to start gnatsd")
	}
	defer server.Shutdown()

	testRPCHappyPath(t, thrift.NewTJSONProtocolFactory())
	testRPCHappyPath(t, thrift.NewTBinaryProtocolFactoryDefault())
	testRPCHappyPath(t, thrift.NewTCompactProtocolFactory())
	testRPCNoServer(t)
}
开发者ID:Workiva,项目名称:thrift-nats,代码行数:14,代码来源:thrift_nats_test.go

示例8: compact

func compact() {
	fmt.Printf("\n ==== demo Thrift Compact Binary serialization ====\n")

	t := thrift.NewTMemoryBufferLen(1024)
	p := thrift.NewTCompactProtocolFactory().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.NewTCompactProtocolFactory().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,代码行数:36,代码来源:serialize.go

示例9: main

func main() {
	flag.Usage = Usage
	server := flag.Bool("server", false, "Run server")
	protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)")
	framed := flag.Bool("framed", false, "Use framed transport")
	buffered := flag.Bool("buffered", false, "Use buffered transport")
	addr := flag.String("addr", nats.DefaultURL, "NATS address to connect to")
	secure := flag.Bool("secure", false, "Use tls secure transport")

	flag.Parse()

	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:
		fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
		Usage()
		os.Exit(1)
	}

	var transportFactory thrift.TTransportFactory
	if *buffered {
		transportFactory = thrift.NewTBufferedTransportFactory(8192)
	} else {
		transportFactory = thrift.NewTTransportFactory()
	}

	if *framed {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	if *server {
		if err := runServer(transportFactory, protocolFactory, *addr, *secure); err != nil {
			fmt.Println("error running server:", err)
		}
	} else {
		if err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil {
			fmt.Println("error running client:", err)
		}
	}
}
开发者ID:Workiva,项目名称:thrift-nats,代码行数:48,代码来源:main.go

示例10: runThriftServer

func runThriftServer(host string, port int, protocol string, framed bool, buffered bool, workerId uint64, datacenterId uint64) {
	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:
		fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
		Usage()
		os.Exit(1)
	}

	var transportFactory thrift.TTransportFactory
	if buffered {
		transportFactory = thrift.NewTBufferedTransportFactory(8192)
	} else {
		transportFactory = thrift.NewTTransportFactory()
	}

	if framed {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	var err error
	var transport thrift.TServerTransport
	transport, err = thrift.NewTServerSocket(fmt.Sprintf("%s:%d", host, port))
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	worker, err := idworker.NewIdWorker(workerId, datacenterId)

	processor := snowflake.NewSnowflakeProcessor(worker)

	if err == nil {
		server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory)
		server.Serve()
	} else {
		log.Fatal(err)
	}
}
开发者ID:vonwenm,项目名称:gosnowflake-1,代码行数:47,代码来源:thriftserver.go

示例11: main

func main() {
	flag.Usage = Usage
	// always be a client in this copy
	//server := flag.Bool("server", false, "Run server")
	protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)")
	framed := flag.Bool("framed", false, "Use framed transport")
	buffered := flag.Bool("buffered", false, "Use buffered transport")
	addr := flag.String("addr", "localhost:9090", "Address to listen to")
	secure := flag.Bool("secure", false, "Use tls secure transport")

	flag.Parse()

	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:
		fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
		Usage()
		os.Exit(1)
	}

	var transportFactory thrift.TTransportFactory
	if *buffered {
		transportFactory = thrift.NewTBufferedTransportFactory(8192)
	} else {
		transportFactory = thrift.NewTTransportFactory()
	}

	if *framed {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	// always be client
	fmt.Printf("*secure = '%v'\n", *secure)
	fmt.Printf("*addr   = '%v'\n", *addr)
	if err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil {
		fmt.Println("error running client:", err)
	}
}
开发者ID:glycerine,项目名称:golang-thrift-minimal-example,代码行数:46,代码来源:main.go

示例12: ToFront

func ToFront(m *calendar.Message) {
	flag.Usage = Usage
	client := flag.Bool("client", true, "Run client")
	protocol := flag.String("P1", "binary", "Specify the protocol (binary, compact, json, simplejson)")
	framed := flag.Bool("framed1", false, "Use framed transport")
	buffered := flag.Bool("buffered1", true, "Use buffered transport")
	addr := flag.String("addr1", "localhost:9090", "Address to listen to")
	secure := flag.Bool("secure1", false, "Use tls secure transport")

	flag.Parse()

	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:
		fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
		Usage()
		os.Exit(1)
	}

	var transportFactory thrift.TTransportFactory
	if *buffered {
		transportFactory = thrift.NewTBufferedTransportFactory(8192)
	} else {
		transportFactory = thrift.NewTTransportFactory()
	}

	if *framed {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	if *client {
		if err := runClient(transportFactory, protocolFactory, *addr, *secure, *m); err != nil {
			fmt.Println("error running client:", err)
		}
	} else {
		fmt.Println("error running client:")
	}
}
开发者ID:wallacexinyu,项目名称:Distributed-Productivity-Calendar,代码行数:46,代码来源:client.go

示例13: startThriftServer

func startThriftServer() {
	protocol := "binary"       // "Specify the protocol (binary, compact, json, simplejson)"
	framed := false            // "Use framed transport"
	buffered := false          // "Use buffered transport"
	addr := ":" + g.ThriftPort // "Address to listen to"
	secure := false            // "Use tls secure transport"

	cpuNum := runtime.NumCPU()
	if cpuNum > 1 {
		runtime.GOMAXPROCS(cpuNum - 1)
	}

	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:
		fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
		os.Exit(1)
	}

	var transportFactory thrift.TTransportFactory
	if buffered {
		transportFactory = thrift.NewTBufferedTransportFactory(8192)
	} else {
		transportFactory = thrift.NewTTransportFactory()
	}

	if framed {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	if err := runServer(transportFactory, protocolFactory, addr, secure); err != nil {
		fmt.Println("error running server:", err)
		g.Log.Error("error running server, error:%s", err.Error())
	}
}
开发者ID:rocflyhi,项目名称:glow,代码行数:43,代码来源:main.go

示例14: Connect

func (self *FlumeClient) Connect() error {

	var tsocket *thrift.TSocket
	var err error
	//创建一个物理连接
	tsocket, err = thrift.NewTSocketTimeout(net.JoinHostPort(self.host, strconv.Itoa(self.port)), 10*time.Second)
	if nil != err {
		log.Printf("FLUME_CLIENT|CREATE TSOCKET|FAIL|%s|%s\n", self.HostPort(), err)
		return err
	}

	self.tsocket = tsocket
	self.transportFactory = thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	//TLV 方式传输
	self.protocolFactory = thrift.NewTCompactProtocolFactory()

	self.clientConn()
	self.status = STATUS_READY
	go self.checkAlive()

	return nil
}
开发者ID:sutoo,项目名称:flume-log-sdk,代码行数:22,代码来源:flume_client.go

示例15: main

func main() {
	flag.Usage = Usage
	server := flag.Bool("server", false, "Run server")
	protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, simplejson)")
	framed := flag.Bool("framed", false, "Use framed transport")

	flag.Parse()

	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:
		fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n")
		Usage()
		os.Exit(1)
	}
	transportFactory := thrift.NewTTransportFactory()
	if *framed {
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	}

	if *server {
		if err := runServer(transportFactory, protocolFactory); err != nil {
			fmt.Println("error running server:", err)
		}
	} else {
		if err := runClient(transportFactory, protocolFactory); err != nil {
			fmt.Println("error running client:", err)
		}
	}
}
开发者ID:lxyu,项目名称:thrift,代码行数:38,代码来源:main.go


注:本文中的git/apache/org/thrift/git/lib/go/thrift.NewTCompactProtocolFactory函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。