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


Golang thrift.NewTBinaryProtocolTransport函数代码示例

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


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

示例1: Call

func (c *client) Call(ctx Context, serviceName, methodName string, req, resp thrift.TStruct) (bool, error) {
	call, err := c.sc.BeginCall(ctx, serviceName+"::"+methodName, &tchannel.CallOptions{Format: tchannel.Thrift})
	if err != nil {
		return false, err
	}

	writer, err := call.Arg2Writer()
	if err != nil {
		return false, err
	}
	if err := writeHeaders(writer, ctx.Headers()); err != nil {
		return false, err
	}
	if err := writer.Close(); err != nil {
		return false, err
	}

	writer, err = call.Arg3Writer()
	if err != nil {
		return false, err
	}

	protocol := thrift.NewTBinaryProtocolTransport(&readWriterTransport{Writer: writer})
	if err := req.Write(protocol); err != nil {
		return false, err
	}
	if err := writer.Close(); err != nil {
		return false, err
	}

	reader, err := call.Response().Arg2Reader()
	if err != nil {
		return false, err
	}

	headers, err := readHeaders(reader)
	if err != nil {
		return false, err
	}
	ctx.SetResponseHeaders(headers)
	if err := reader.Close(); err != nil {
		return false, err
	}

	success := !call.Response().ApplicationError()
	reader, err = call.Response().Arg3Reader()
	if err != nil {
		return success, err
	}

	protocol = thrift.NewTBinaryProtocolTransport(&readWriterTransport{Reader: reader})
	if err := resp.Read(protocol); err != nil {
		return success, err
	}
	if err := reader.Close(); err != nil {
		return success, err
	}

	return success, nil
}
开发者ID:pengzhai,项目名称:tchannel,代码行数:60,代码来源:client.go

示例2: handle

func (s *Server) handle(origCtx context.Context, handler handler, method string, call *tchannel.InboundCall) error {
	reader, err := call.Arg2Reader()
	if err != nil {
		return err
	}
	headers, err := readHeaders(reader)
	if err != nil {
		return err
	}
	if err := reader.Close(); err != nil {
		return err
	}

	reader, err = call.Arg3Reader()
	if err != nil {
		return err
	}

	ctx := WithHeaders(origCtx, headers)
	protocol := thrift.NewTBinaryProtocolTransport(&readWriterTransport{Reader: reader})
	success, resp, err := handler.server.Handle(ctx, method, protocol)
	if err != nil {
		reader.Close()
		call.Response().SendSystemError(err)
		return nil
	}
	if err := reader.Close(); err != nil {
		return err
	}

	if !success {
		call.Response().SetApplicationError()
	}

	writer, err := call.Response().Arg2Writer()
	if err != nil {
		return err
	}

	if err := writeHeaders(writer, ctx.ResponseHeaders()); err != nil {
		return err
	}
	if err := writer.Close(); err != nil {
		return err
	}

	writer, err = call.Response().Arg3Writer()
	protocol = thrift.NewTBinaryProtocolTransport(&readWriterTransport{Writer: writer})
	resp.Write(protocol)
	err = writer.Close()

	if handler.postResponseCB != nil {
		handler.postResponseCB(method, resp)
	}

	return err
}
开发者ID:glycerine,项目名称:tchannel-go,代码行数:57,代码来源:server.go

示例3: spans

func (h *scribeHandler) spans() []*zipkincore.Span {
	h.RLock()
	defer h.RUnlock()
	spans := []*zipkincore.Span{}
	for _, m := range h.entries {
		decoded, err := base64.StdEncoding.DecodeString(m.GetMessage())
		if err != nil {
			h.t.Error(err)
			continue
		}
		buffer := thrift.NewTMemoryBuffer()
		if _, err := buffer.Write(decoded); err != nil {
			h.t.Error(err)
			continue
		}
		transport := thrift.NewTBinaryProtocolTransport(buffer)
		zs := &zipkincore.Span{}
		if err := zs.Read(transport); err != nil {
			h.t.Error(err)
			continue
		}
		spans = append(spans, zs)
	}
	return spans
}
开发者ID:jllopis,项目名称:kit,代码行数:25,代码来源:collector_test.go

示例4: kafkaSerialize

func kafkaSerialize(s *Span) []byte {
	t := thrift.NewTMemoryBuffer()
	p := thrift.NewTBinaryProtocolTransport(t)
	if err := s.Encode().Write(p); err != nil {
		panic(err)
	}
	return t.Buffer.Bytes()
}
开发者ID:zyanho,项目名称:kit,代码行数:8,代码来源:kafka.go

示例5: scribeSerialize

func scribeSerialize(s *Span) string {
	t := thrift.NewTMemoryBuffer()
	p := thrift.NewTBinaryProtocolTransport(t)
	if err := s.Encode().Write(p); err != nil {
		panic(err)
	}
	return base64.StdEncoding.EncodeToString(t.Buffer.Bytes())
}
开发者ID:xiejianzheng,项目名称:goddd,代码行数:8,代码来源:scribe.go

示例6: spanToBytes

func spanToBytes(span *zipkin.Span) ([]byte, error) {
	t := thrift.NewTMemoryBuffer()
	p := thrift.NewTBinaryProtocolTransport(t)
	err := span.Write(p)
	if err != nil {
		return nil, err
	}
	return t.Buffer.Bytes(), nil
}
开发者ID:adriancole,项目名称:go-zipkin,代码行数:9,代码来源:scribe.go

示例7: pub

func (z *zipkin) pub(s *zipkincore.Span, pr sarama.SyncProducer) {
	t := thrift.NewTMemoryBufferLen(1024)
	p := thrift.NewTBinaryProtocolTransport(t)
	if err := s.Write(p); err != nil {
		return
	}

	m := &sarama.ProducerMessage{
		Topic: z.opts.Topic,
		Value: sarama.ByteEncoder(t.Buffer.Bytes()),
	}
	pr.SendMessage(m)
}
开发者ID:jelmersnoeck,项目名称:go-platform,代码行数:13,代码来源:zipkin.go

示例8: SerializeThrift

// SerializeThrift takes a thrift struct and returns the serialized bytes
// of that struct using the thrift binary protocol. This is a temporary
// measure before frames can be forwarded directly past the endpoint to the proper
// destinaiton.
func SerializeThrift(s athrift.TStruct) ([]byte, error) {
	var b []byte
	var buffer = bytes.NewBuffer(b)

	transport := athrift.NewStreamTransportW(buffer)
	if err := s.Write(athrift.NewTBinaryProtocolTransport(transport)); err != nil {
		return nil, err
	}

	if err := transport.Flush(); err != nil {
		return nil, err
	}
	return buffer.Bytes(), nil
}
开发者ID:dansimau,项目名称:ringpop-go,代码行数:18,代码来源:forwarder_test.go

示例9: newConnection

func (c *ScribeCollector) newConnection() (scribe.Scribe, error) {
	addr, err := net.ResolveTCPAddr("tcp", c.addr)
	if err != nil {
		return nil, err
	}
	socket := thrift.NewTSocketFromAddrTimeout(addr, timeout)
	transport := thrift.NewTFramedTransport(socket)
	if err := transport.Open(); err != nil {
		return nil, err
	}
	proto := thrift.NewTBinaryProtocolTransport(transport)
	s := scribe.NewScribeClientProtocol(transport, proto, proto)
	return s, nil
}
开发者ID:adriancole,项目名称:go-zipkin,代码行数:14,代码来源:scribe.go

示例10: deserializeSpan

func deserializeSpan(t *testing.T, e sarama.Encoder) *zipkincore.Span {
	bytes, err := e.Encode()
	if err != nil {
		t.Errorf("error in encoding: %v", err)
	}
	s := zipkincore.NewSpan()
	mb := thrift.NewTMemoryBufferLen(len(bytes))
	mb.Write(bytes)
	mb.Flush()
	pt := thrift.NewTBinaryProtocolTransport(mb)
	err = s.Read(pt)
	if err != nil {
		t.Errorf("error in decoding: %v", err)
	}
	return s
}
开发者ID:qband,项目名称:down,代码行数:16,代码来源:kafka_test.go

示例11: scribeClientFactory

func scribeClientFactory(addr string, timeout time.Duration) func() (scribe.Scribe, error) {
	return func() (scribe.Scribe, error) {
		a, err := net.ResolveTCPAddr("tcp", addr)
		if err != nil {
			return nil, err
		}
		socket := thrift.NewTSocketFromAddrTimeout(a, timeout)
		transport := thrift.NewTFramedTransport(socket)
		if err := transport.Open(); err != nil {
			socket.Close()
			return nil, err
		}
		proto := thrift.NewTBinaryProtocolTransport(transport)
		client := scribe.NewScribeClientProtocol(transport, proto, proto)
		return client, nil
	}
}
开发者ID:xiejianzheng,项目名称:goddd,代码行数:17,代码来源:scribe.go

示例12: newConnection

func newConnection(n *node, keyspace string, timeout time.Duration, authentication map[string]string) (*connection, error) {

	addr, err := net.ResolveTCPAddr("tcp", n.node)
	if err != nil {
		return nil, err
	}

	c := &connection{node: n}

	c.socket = thrift.NewTSocketFromAddrTimeout(addr, timeout)

	c.transport = thrift.NewTFramedTransport(c.socket)
	protocol := thrift.NewTBinaryProtocolTransport(c.transport)
	c.client = cassandra.NewCassandraClientProtocol(c.transport, protocol, protocol)

	if err = c.transport.Open(); err != nil {
		return nil, err
	}

	version, err := c.client.DescribeVersion()
	if err != nil {
		c.close()
		return nil, err
	}
	versionComponents := strings.Split(version, ".")
	if len(versionComponents) < 1 {
		return nil, errors.New(fmt.Sprint("Cannot parse the Thrift API version number: ", version))
	}
	majorVersion, err := strconv.Atoi(versionComponents[0])
	if err != nil {
		return nil, errors.New(fmt.Sprint("Cannot parse the Thrift API version number: ", version))
	}
	if majorVersion < LOWEST_COMPATIBLE_VERSION {
		return nil, errors.New(fmt.Sprint("Unsupported Thrift API version, lowest supported is ", LOWEST_COMPATIBLE_VERSION,
			", server reports ", majorVersion))
	}

	if len(authentication) > 0 {
		ar := cassandra.NewAuthenticationRequest()
		ar.Credentials = authentication
		err := c.client.Login(ar)
		if err != nil {
			c.close()
			switch err.(type) {
			case *cassandra.AuthenticationException:
				return nil, errors.New("Login error: cannot authenticate with the given credentials")
			case *cassandra.AuthorizationException:
				return nil, errors.New("Login error: the given credentials are not authorized to access the server")
			default:
				return nil, err
			}
		}
	}

	err = c.client.SetKeyspace(keyspace)
	if err != nil {
		c.close()
		switch err.(type) {
		case *cassandra.InvalidRequestException:
			err = errors.New("Cannot set the keyspace " + keyspace)
		}
		return nil, err
	}

	return c, nil
}
开发者ID:apesternikov,项目名称:gossie,代码行数:66,代码来源:connection.go

示例13: DeserializeThrift

// DeserializeThrift takes a byte slice and attempts to write it into the
// given thrift struct using the thrift binary protocol. This is a temporary
// measure before frames can be forwarded directly past the endpoint to the proper
// destinaiton.
func DeserializeThrift(b []byte, s athrift.TStruct) error {
	reader := bytes.NewReader(b)
	transport := athrift.NewStreamTransportR(reader)
	return s.Read(athrift.NewTBinaryProtocolTransport(transport))
}
开发者ID:dansimau,项目名称:ringpop-go,代码行数:9,代码来源:forwarder_test.go

示例14: RemainingBytes

func (t *readWriterTransport) RemainingBytes() uint64 {
	const maxSize = ^uint64(0)
	return maxSize
}

var _ thrift.TRichTransport = &readWriterTransport{}

type thriftProtocol struct {
	transport *readWriterTransport
	protocol  *thrift.TBinaryProtocol
}

var thriftProtocolPool = sync.Pool{
	New: func() interface{} {
		transport := &readWriterTransport{}
		protocol := thrift.NewTBinaryProtocolTransport(transport)
		return &thriftProtocol{transport, protocol}
	},
}

func getProtocolWriter(writer io.Writer) *thriftProtocol {
	wp := thriftProtocolPool.Get().(*thriftProtocol)
	wp.transport.Reader = nil
	wp.transport.Writer = writer
	return wp
}

func getProtocolReader(reader io.Reader) *thriftProtocol {
	wp := thriftProtocolPool.Get().(*thriftProtocol)
	wp.transport.Reader = reader
	wp.transport.Writer = nil
开发者ID:uber,项目名称:tchannel-go,代码行数:31,代码来源:transport.go


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