當前位置: 首頁>>代碼示例>>Golang>>正文


Golang TStruct.Write方法代碼示例

本文整理匯總了Golang中github.com/apache/thrift/lib/go/thrift.TStruct.Write方法的典型用法代碼示例。如果您正苦於以下問題:Golang TStruct.Write方法的具體用法?Golang TStruct.Write怎麽用?Golang TStruct.Write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/apache/thrift/lib/go/thrift.TStruct的用法示例。


在下文中一共展示了TStruct.Write方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

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

示例4: 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.Write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。