本文整理汇总了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()
}
示例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
}
示例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)
}
}
示例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()
}
示例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)}
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
}
}
示例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)
}
}
示例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)
}
}
示例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:")
}
}
示例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())
}
}
示例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
}
示例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)
}
}
}