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


Golang thrift.NewTBinaryProtocolFactoryDefault函数代码示例

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


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

示例1: TestTBinaryProtocol

// Run test suite using TBinaryProtocol
func TestTBinaryProtocol(t *testing.T) {
	RunSocketTestSuite(t,
		thrift.NewTBinaryProtocolFactoryDefault(),
		thrift.NewTTransportFactory())
	RunSocketTestSuite(t,
		thrift.NewTBinaryProtocolFactoryDefault(),
		thrift.NewTBufferedTransportFactory(8912))
	RunSocketTestSuite(t,
		thrift.NewTBinaryProtocolFactoryDefault(),
		thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
}
开发者ID:ConfusedReality,项目名称:pkg_serialization_thrift,代码行数:12,代码来源:protocols_test.go

示例2: newProtocolFactory

func newProtocolFactory(protocol int) (thrift.TProtocolFactory, error) {
	switch protocol {
	case TBinaryProtocol:
		return thrift.NewTBinaryProtocolFactoryDefault(), nil
	case TCompactProtocol:
		return thrift.NewTCompactProtocolFactory(), nil
	case TJSONProtocol:
		return thrift.NewTJSONProtocolFactory(), nil
	case TSimpleJSONProtocol:
		return thrift.NewTSimpleJSONProtocolFactory(), nil
	}

	return nil, errors.New(fmt.Sprint("invalid protocol:", protocol))
}
开发者ID:mohanarpit,项目名称:goh,代码行数:14,代码来源:goh.go

示例3: main

func main() {
	flag.Usage = Usage
	var client bool
	var server bool
	var protocol string
	var framed bool
	var useHttp bool
	var help bool

	flag.BoolVar(&client, "client", false, "Run client")
	flag.BoolVar(&server, "server", false, "Run server")
	flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson)")
	flag.BoolVar(&framed, "framed", false, "Use framed transport")
	flag.BoolVar(&useHttp, "http", false, "Use http")
	flag.BoolVar(&help, "help", false, "See usage string")
	flag.Parse()
	if help || (client && server) || !(client || server) {
		fmt.Print("flag.NArg() == ", flag.NArg(), "\n")
		flag.Usage()
	}
	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 client {
		RunClient(transportFactory, protocolFactory)
	} else if server {
		RunServer(transportFactory, protocolFactory)
	} else {
		flag.Usage()
	}
	os.Exit(0)
}
开发者ID:pombredanne,项目名称:thrift4go,代码行数:49,代码来源:main.go

示例4: TestInitTwoServers

func TestInitTwoServers(t *testing.T) {
	var err error
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	transportFactory := thrift.NewTTransportFactory()
	transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	addr = FindAvailableTCPServerPort()
	serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
	if err != nil {
		t.Fatal("Unable to create server socket", err)
	}
	server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)

	firstProcessor := multiplexedprotocoltest.NewFirstProcessor(&FirstImpl{})
	processor.RegisterProcessor("FirstService", firstProcessor)

	secondProcessor := multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{})
	processor.RegisterProcessor("SecondService", secondProcessor)

	go server.Serve()
}
开发者ID:GDGroup,项目名称:thrift,代码行数:20,代码来源:multiplexed_protocol_test.go

示例5: TestBinaryProtocol

func TestBinaryProtocol(t *testing.T) {
	pf := thrift.NewTBinaryProtocolFactoryDefault()
	tf := thrift.NewTTransportFactory()

	addr, _ := net.ResolveTCPAddr("tcp", "localhost:8080")

	channel := thrift.NewTSocketAddr(addr)
	defer channel.Close()

	if openErr := channel.Open(); openErr != nil {
		t.Fatalf("Could not open channel due to '%q'.", openErr)
	}

	effectiveTransport := tf.GetTransport(channel)

	client := NewContainerOfEnumsTestServiceClientFactory(effectiveTransport, pf)

	var request *ContainerOfEnums = NewContainerOfEnums()

	var response *ContainerOfEnums
	var anomaly error

	if response, anomaly = client.Echo(request); anomaly != nil {
		t.Fatalf("Could not get response due to '%q'.", anomaly)
	}

	if request.First != response.First {
		t.Errorf("request.First (%q) != response.First (%q)", request.First, response.First)
	}

	if request.IsSetFirst() != response.IsSetFirst() {
		t.Errorf("request.IsSetFirst() (%q) != response.IsSetFirst() (%q).", request.IsSetFirst(), response.IsSetFirst())
	}

	if request.Second != response.Second {
		t.Errorf("request.Second (%q) != response.Second (%q).", request.Second, response.Second)
	}

	if request.IsSetSecond() != response.IsSetSecond() {
		t.Errorf("request.IsSetSecond() (%q) != response.IsSetSecond() (%q).", request.IsSetSecond(), response.IsSetSecond())
	}

	if request.Third != response.Third {
		t.Errorf("request.Third (%q) != response.Third (%q).", request.Third, response.Third)
	}

	if request.IsSetThird() != response.IsSetThird() {
		t.Errorf("request.IsSetThird() (%q) != response.IsSetThird() (%q).", request.IsSetThird(), response.IsSetThird())
	}

	if request.OptionalFourth != response.OptionalFourth {
		t.Errorf("request.OptionalFourth (%q) != response.OptionalFourth (%q).", request.OptionalFourth, response.OptionalFourth)
	}

	if request.IsSetOptionalFourth() != response.IsSetOptionalFourth() {
		t.Errorf("request.IsSetOptionalFourth() (%q) != response.IsSetOptionalFourth() (%q).", request.IsSetOptionalFourth(), response.IsSetOptionalFourth())
	}

	if request.OptionalFifth != response.OptionalFifth {
		t.Errorf("request.OptionalFifth (%q) != response.OptionalFifth (%q).", request.OptionalFifth, response.OptionalFifth)
	}

	if request.IsSetOptionalFifth() != response.IsSetOptionalFifth() {
		t.Errorf("request.IsSetOptionalFifth() (%q) != response.IsSetOptionalFifth() (%q).", request.IsSetOptionalFifth(), response.IsSetOptionalFifth())
	}

	if request.OptionalSixth != response.OptionalSixth {
		t.Errorf("request.OptionalSixth (%q) != response.OptionalSixth (%q).", request.OptionalSixth, response.OptionalSixth)
	}

	if request.IsSetOptionalSixth() != response.IsSetOptionalSixth() {
		t.Errorf("request.IsSetOptionalSixth() (%q) != response.IsSetOptionalSixth() (%q).", request.IsSetOptionalSixth(), response.IsSetOptionalSixth())
	}

	if request.DefaultSeventh != response.DefaultSeventh {
		t.Errorf("request.DefaultSeventh (%q) != response.DefaultSeventh (%q).", request.DefaultSeventh, response.DefaultSeventh)
	}

	if request.IsSetDefaultSeventh() != response.IsSetDefaultSeventh() {
		t.Errorf("request.IsSetDefaultSeventh() (%q) != response.IsSetDefaultSeventh() (%q).", request.IsSetDefaultSeventh(), response.IsSetDefaultSeventh())
	}

	if request.DefaultEighth != response.DefaultEighth {
		t.Errorf("request.DefaultEighth (%q) != response.DefaultEighth (%q).", request.DefaultEighth, response.DefaultEighth)
	}

	if request.IsSetDefaultEighth() != response.IsSetDefaultEighth() {
		t.Errorf("request.IsSetDefaultEighth() (%q) != response.IsSetDefaultEighth() (%q).", request.IsSetDefaultEighth(), response.IsSetDefaultEighth())
	}

	if request.DefaultNineth != response.DefaultNineth {
		t.Errorf("request.DefaultNineth (%q) != response.DefaultNineth (%q).", request.DefaultNineth, response.DefaultNineth)
	}

	if request.IsSetDefaultNineth() != response.IsSetDefaultNineth() {
		t.Errorf("request.IsSetDefaultNineth() (%q) != response.IsSetDefaultNineth() (%q).", request.IsSetDefaultNineth(), response.IsSetDefaultNineth())
	}

	request.First = UndefinedValues_Two
	request.Second = DefinedValues_Two
//.........这里部分代码省略.........
开发者ID:pomack,项目名称:thrift4go,代码行数:101,代码来源:exercise_test.go

示例6: 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 := thrifttest.NewThriftTestClientFactory(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 "testVoid":
		if flag.NArg()-1 != 0 {
			fmt.Fprintln(os.Stderr, "TestVoid requires 0 args")
			flag.Usage()
		}
		fmt.Print(client.TestVoid())
		fmt.Print("\n")
		break
	case "testString":
		if flag.NArg()-1 != 1 {
//.........这里部分代码省略.........
开发者ID:sktzwhj,项目名称:thrift-0.9.3,代码行数:101,代码来源:thrift_test-remote.go

示例7: 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 help bool
	var parsedUrl url.URL
	var trans thrift.TTransport
	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.BoolVar(&help, "help", false, "See usage string")
	flag.Parse()
	if help || flag.NArg() == 0 {
		flag.Usage()
	}

	if len(urlString) > 0 {
		parsedUrl, err := url.Parse(urlString)
		if err != nil {
			fmt.Fprint(os.Stderr, "Error parsing URL: ", err.Error(), "\n")
			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.Fprint(os.Stderr, "Error parsing URL: ", err.Error(), "\n")
			flag.Usage()
		}
	}

	cmd := flag.Arg(0)
	var err error
	if useHttp {
		trans, err = thrift.NewTHttpClient(parsedUrl.String())
	} else {
		addr, err := net.ResolveTCPAddr("tcp", fmt.Sprint(host, ":", port))
		if err != nil {
			fmt.Fprint(os.Stderr, "Error resolving address", err.Error())
			os.Exit(1)
		}
		trans, err = thrift.NewTNonblockingSocketAddr(addr)
		if framed {
			trans = thrift.NewTFramedTransport(trans)
		}
	}
	if err != nil {
		fmt.Fprint(os.Stderr, "Error creating transport", err.Error())
		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.Fprint(os.Stderr, "Invalid protocol specified: ", protocol, "\n")
		Usage()
		os.Exit(1)
	}
	client := simple.NewContainerOfEnumsTestServiceClientFactory(trans, protocolFactory)
	if err = trans.Open(); err != nil {
		fmt.Fprint(os.Stderr, "Error opening socket to ", host, ":", port, " ", err.Error())
		os.Exit(1)
	}

	switch cmd {
	case "echo":
		if flag.NArg()-1 != 1 {
			fmt.Fprint(os.Stderr, "Echo requires 1 args\n")
			flag.Usage()
		}
		arg33 := flag.Arg(1)
		mbTrans34 := thrift.NewTMemoryBufferLen(len(arg33))
		defer mbTrans34.Close()
		_, err35 := mbTrans34.WriteString(arg33)
		if err35 != nil {
			Usage()
			return
		}
		factory36 := thrift.NewTSimpleJSONProtocolFactory()
//.........这里部分代码省略.........
开发者ID:pablo-meier,项目名称:thrift4go,代码行数:101,代码来源:ContainerOfEnumsTestService-remote.go

示例8: FindAll

package main

import (
	"errors"
	"fmt"
	"os"

	"rpc"
	"thrift"
)

var (
	transportFactory    = thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory     = thrift.NewTBinaryProtocolFactoryDefault()
	errUserOrPwdInvalid = errors.New("userid or password invalid")
)

const (
	remoteAddr = "192.168.1.241:8000"
)

type rpcService struct {
}

func (rs *rpcService) FindAll(userid int64, password string, param map[string]string) (res []string, err error) {
	if userid != 1 || password != "123456" || len(param) == 0 {
		err = errUserOrPwdInvalid
		return
	}

	for k, v := range param {
开发者ID:viney,项目名称:gothrift,代码行数:31,代码来源:main.go

示例9: 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 := thrifttest.NewSecondServiceClientFactory(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 "blahBlah":
		if flag.NArg()-1 != 0 {
			fmt.Fprintln(os.Stderr, "BlahBlah requires 0 args")
			flag.Usage()
		}
		fmt.Print(client.BlahBlah())
		fmt.Print("\n")
		break
	case "secondtestString":
		if flag.NArg()-1 != 1 {
//.........这里部分代码省略.........
开发者ID:sktzwhj,项目名称:thrift-0.9.3,代码行数:101,代码来源:second_service-remote.go

示例10: 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 := stress.NewServiceClientFactory(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 "echoVoid":
		if flag.NArg()-1 != 0 {
			fmt.Fprintln(os.Stderr, "EchoVoid requires 0 args")
			flag.Usage()
		}
		fmt.Print(client.EchoVoid())
		fmt.Print("\n")
		break
	case "echoByte":
		if flag.NArg()-1 != 1 {
//.........这里部分代码省略.........
开发者ID:sktzwhj,项目名称:thrift-0.9.3,代码行数:101,代码来源:service-remote.go

示例11: 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 help bool
	var parsedUrl url.URL
	var trans thrift.TTransport
	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.BoolVar(&help, "help", false, "See usage string")
	flag.Parse()
	if help || flag.NArg() == 0 {
		flag.Usage()
	}

	if len(urlString) > 0 {
		parsedUrl, err := url.Parse(urlString)
		if err != nil {
			fmt.Fprint(os.Stderr, "Error parsing URL: ", err.Error(), "\n")
			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.Fprint(os.Stderr, "Error parsing URL: ", err.Error(), "\n")
			flag.Usage()
		}
	}

	cmd := flag.Arg(0)
	var err error
	if useHttp {
		trans, err = thrift.NewTHttpClient(parsedUrl.String())
	} else {
		addr, err := net.ResolveTCPAddr("tcp", fmt.Sprint(host, ":", port))
		if err != nil {
			fmt.Fprint(os.Stderr, "Error resolving address", err.Error())
			os.Exit(1)
		}
		trans, err = thrift.NewTNonblockingSocketAddr(addr)
		if framed {
			trans = thrift.NewTFramedTransport(trans)
		}
	}
	if err != nil {
		fmt.Fprint(os.Stderr, "Error creating transport", err.Error())
		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.Fprint(os.Stderr, "Invalid protocol specified: ", protocol, "\n")
		Usage()
		os.Exit(1)
	}
	client := librarytest.NewServiceForExceptionWithAMapClientFactory(trans, protocolFactory)
	if err = trans.Open(); err != nil {
		fmt.Fprint(os.Stderr, "Error opening socket to ", host, ":", port, " ", err.Error())
		os.Exit(1)
	}

	switch cmd {
	case "methodThatThrowsAnException":
		if flag.NArg()-1 != 0 {
			fmt.Fprint(os.Stderr, "MethodThatThrowsAnException requires 0 args\n")
			flag.Usage()
		}
		fmt.Print(client.MethodThatThrowsAnException())
		fmt.Print("\n")
		break
	case "":
		Usage()
		break
	default:
		fmt.Fprint(os.Stderr, "Invalid function ", cmd, "\n")
	}
//.........这里部分代码省略.........
开发者ID:mohanarpit,项目名称:goh,代码行数:101,代码来源:ServiceForExceptionWithAMap-remote.go

示例12: 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 help bool
	var url http.URL
	var trans thrift.TTransport
	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.BoolVar(&help, "help", false, "See usage string")
	flag.Parse()
	if help || flag.NArg() == 0 {
		flag.Usage()
	}

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

	cmd := flag.Arg(0)
	var err error
	if useHttp {
		trans, err = thrift.NewTHttpClient(url.Raw)
	} else {
		addr, err := net.ResolveTCPAddr("tcp", fmt.Sprint(host, ":", port))
		if err != nil {
			fmt.Fprint(os.Stderr, "Error resolving address", err.Error())
			os.Exit(1)
		}
		trans, err = thrift.NewTNonblockingSocketAddr(addr)
		if framed {
			trans = thrift.NewTFramedTransport(trans)
		}
	}
	if err != nil {
		fmt.Fprint(os.Stderr, "Error creating transport", err.Error())
		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.Fprint(os.Stderr, "Invalid protocol specified: ", protocol, "\n")
		Usage()
		os.Exit(1)
	}
	client := hive_metastore.NewThriftHiveMetastoreClientFactory(trans, protocolFactory)
	if err = trans.Open(); err != nil {
		fmt.Fprint(os.Stderr, "Error opening socket to ", host, ":", port, " ", err.Error())
		os.Exit(1)
	}

	switch cmd {
	case "create_database":
		if flag.NArg()-1 != 1 {
			fmt.Fprint(os.Stderr, "CreateDatabase requires 1 args\n")
			flag.Usage()
		}
		arg1889 := flag.Arg(1)
		mbTrans1890 := thrift.NewTMemoryBufferLen(len(arg1889))
		defer mbTrans1890.Close()
		_, err1891 := mbTrans1890.WriteString(arg1889)
		if err1891 != nil {
			Usage()
			return
		}
		factory1892 := thrift.NewTSimpleJSONProtocolFactory()
//.........这里部分代码省略.........
开发者ID:sundy-li,项目名称:hive,代码行数:101,代码来源:ThriftHiveMetastore-remote.go

示例13: 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 help bool
	var parsedUrl url.URL
	var trans thrift.TTransport
	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.BoolVar(&help, "help", false, "See usage string")
	flag.Parse()
	if help || flag.NArg() == 0 {
		flag.Usage()
	}

	if len(urlString) > 0 {
		parsedUrl, err := url.Parse(urlString)
		if err != nil {
			fmt.Fprint(os.Stderr, "Error parsing URL: ", err.Error(), "\n")
			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.Fprint(os.Stderr, "Error parsing URL: ", err.Error(), "\n")
			flag.Usage()
		}
	}

	cmd := flag.Arg(0)
	var err error
	if useHttp {
		trans, err = thrift.NewTHttpClient(parsedUrl.String())
	} else {
		addr, err := net.ResolveTCPAddr("tcp", fmt.Sprint(host, ":", port))
		if err != nil {
			fmt.Fprint(os.Stderr, "Error resolving address", err.Error())
			os.Exit(1)
		}
		trans, err = thrift.NewTNonblockingSocketAddr(addr)
		if framed {
			trans = thrift.NewTFramedTransport(trans)
		}
	}
	if err != nil {
		fmt.Fprint(os.Stderr, "Error creating transport", err.Error())
		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.Fprint(os.Stderr, "Invalid protocol specified: ", protocol, "\n")
		Usage()
		os.Exit(1)
	}
	client := Cassandra.NewCassandraClientFactory(trans, protocolFactory)
	if err = trans.Open(); err != nil {
		fmt.Fprint(os.Stderr, "Error opening socket to ", host, ":", port, " ", err.Error())
		os.Exit(1)
	}

	switch cmd {
	case "login":
		if flag.NArg()-1 != 1 {
			fmt.Fprint(os.Stderr, "Login requires 1 args\n")
			flag.Usage()
		}
		arg958 := flag.Arg(1)
		mbTrans959 := thrift.NewTMemoryBufferLen(len(arg958))
		defer mbTrans959.Close()
		_, err960 := mbTrans959.WriteString(arg958)
		if err960 != nil {
			Usage()
			return
		}
		factory961 := thrift.NewTSimpleJSONProtocolFactory()
//.........这里部分代码省略.........
开发者ID:tonnerre,项目名称:go-cassandra,代码行数:101,代码来源:Cassandra-remote.go

示例14: 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 help bool
	var parsedUrl url.URL
	var trans thrift.TTransport
	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.BoolVar(&help, "help", false, "See usage string")
	flag.Parse()
	if help || flag.NArg() == 0 {
		flag.Usage()
	}

	if len(urlString) > 0 {
		parsedUrl, err := url.Parse(urlString)
		if err != nil {
			fmt.Fprint(os.Stderr, "Error parsing URL: ", err.Error(), "\n")
			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.Fprint(os.Stderr, "Error parsing URL: ", err.Error(), "\n")
			flag.Usage()
		}
	}

	cmd := flag.Arg(0)
	var err error
	if useHttp {
		trans, err = thrift.NewTHttpClient(parsedUrl.String())
	} else {
		addr, err := net.ResolveTCPAddr("tcp", fmt.Sprint(host, ":", port))
		if err != nil {
			fmt.Fprint(os.Stderr, "Error resolving address", err.Error())
			os.Exit(1)
		}
		trans, err = thrift.NewTNonblockingSocketAddr(addr)
		if framed {
			trans = thrift.NewTFramedTransport(trans)
		}
	}
	if err != nil {
		fmt.Fprint(os.Stderr, "Error creating transport", err.Error())
		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.Fprint(os.Stderr, "Invalid protocol specified: ", protocol, "\n")
		Usage()
		os.Exit(1)
	}
	client := tutorial.NewCalculatorClientFactory(trans, protocolFactory)
	if err = trans.Open(); err != nil {
		fmt.Fprint(os.Stderr, "Error opening socket to ", host, ":", port, " ", err.Error())
		os.Exit(1)
	}

	switch cmd {
	case "ping":
		if flag.NArg()-1 != 0 {
			fmt.Fprint(os.Stderr, "Ping requires 0 args\n")
			flag.Usage()
		}
		fmt.Print(client.Ping())
		fmt.Print("\n")
		break
	case "add":
		if flag.NArg()-1 != 2 {
			fmt.Fprint(os.Stderr, "Add requires 2 args\n")
			flag.Usage()
		}
		tmp0, err62 := (strconv.Atoi(flag.Arg(1)))
//.........这里部分代码省略.........
开发者ID:mohanarpit,项目名称:goh,代码行数:101,代码来源:Calculator-remote.go

示例15: GetServerParams

func GetServerParams(
	host string,
	port int64,
	domain_socket string,
	transport string,
	protocol string,
	ssl bool,
	certPath string,
	handler thrifttest.ThriftTest) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, error) {

	var err error
	hostPort := fmt.Sprintf("%s:%d", host, port)

	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:
		return nil, nil, nil, nil, fmt.Errorf("Invalid protocol specified %s", protocol)
	}
	if debugServerProtocol {
		protocolFactory = thrift.NewTDebugProtocolFactory(protocolFactory, "server:")
	}

	var serverTransport thrift.TServerTransport
	if ssl {
		cfg := new(tls.Config)
		if cert, err := tls.LoadX509KeyPair(certPath+"/server.crt", certPath+"/server.key"); err != nil {
			return nil, nil, nil, nil, err
		} else {
			cfg.Certificates = append(cfg.Certificates, cert)
		}
		serverTransport, err = thrift.NewTSSLServerSocket(hostPort, cfg)
	} else {
		if domain_socket != "" {
			serverTransport, err = thrift.NewTServerSocket(domain_socket)
		} else {
			serverTransport, err = thrift.NewTServerSocket(hostPort)
		}
	}
	if err != nil {
		return nil, nil, nil, nil, err
	}

	var transportFactory thrift.TTransportFactory

	switch transport {
	case "http":
		// there is no such factory, and we don't need any
		transportFactory = nil
	case "framed":
		transportFactory = thrift.NewTTransportFactory()
		transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
	case "buffered":
		transportFactory = thrift.NewTBufferedTransportFactory(8192)
	case "zlib":
		transportFactory = thrift.NewTZlibTransportFactory(zlib.BestCompression)
	case "":
		transportFactory = thrift.NewTTransportFactory()
	default:
		return nil, nil, nil, nil, fmt.Errorf("Invalid transport specified %s", transport)
	}
	processor := thrifttest.NewThriftTestProcessor(handler)

	return processor, serverTransport, transportFactory, protocolFactory, nil
}
开发者ID:ChristopherRogers,项目名称:thrift,代码行数:72,代码来源:server.go


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