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


Golang thrift.TStruct类代码示例

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


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

示例1: readResponse

// readResponse reads the response struct into resp, and returns:
// (response headers, whether there was an application error, unexpected error).
func readResponse(response *tchannel.OutboundCallResponse, resp thrift.TStruct) (map[string]string, bool, error) {
	reader, err := response.Arg2Reader()
	if err != nil {
		return nil, false, err
	}

	headers, err := readHeaders(reader)
	if err != nil {
		return nil, false, err
	}

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

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

	wp := getProtocolReader(reader)
	if err := resp.Read(wp.protocol); err != nil {
		thriftProtocolPool.Put(wp)
		return headers, success, err
	}
	thriftProtocolPool.Put(wp)
	return headers, success, reader.Close()
}
开发者ID:dansimau,项目名称:ringpop-go,代码行数:31,代码来源:client.go

示例2: 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

示例3: writeArgs

func writeArgs(call *tchannel.OutboundCall, headers map[string]string, req thrift.TStruct) error {
	writer, err := call.Arg2Writer()
	if err != nil {
		return err
	}
	if err := writeHeaders(writer, headers); err != nil {
		return err
	}
	if err := writer.Close(); err != nil {
		return err
	}

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

	wp := getProtocolWriter(writer)
	if err := req.Write(wp.protocol); err != nil {
		thriftProtocolPool.Put(wp)
		return err
	}
	thriftProtocolPool.Put(wp)
	return writer.Close()
}
开发者ID:dansimau,项目名称:ringpop-go,代码行数:25,代码来源:client.go

示例4: 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

示例5: 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

示例6: ReadStruct

// ReadStruct reads the given Thrift struct. It pools TProtocols.
func ReadStruct(reader io.Reader, s thrift.TStruct) error {
	wp := getProtocolReader(reader)
	err := s.Read(wp.protocol)
	thriftProtocolPool.Put(wp)
	return err
}
开发者ID:gosuper,项目名称:tchannel-go,代码行数:7,代码来源:struct.go

示例7: WriteStruct

// WriteStruct writes the given Thrift struct to a writer. It pools TProtocols.
func WriteStruct(writer io.Writer, s thrift.TStruct) error {
	wp := getProtocolWriter(writer)
	err := s.Write(wp.protocol)
	thriftProtocolPool.Put(wp)
	return err
}
开发者ID:gosuper,项目名称:tchannel-go,代码行数:7,代码来源:struct.go


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