本文整理匯總了Golang中google/golang.org/grpc/transport.Stream.Read方法的典型用法代碼示例。如果您正苦於以下問題:Golang Stream.Read方法的具體用法?Golang Stream.Read怎麽用?Golang Stream.Read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google/golang.org/grpc/transport.Stream
的用法示例。
在下文中一共展示了Stream.Read方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: forwardDataFrames
// forwardDataFrames moves data from one gRPC transport `Stream` to another in async fashion.
// It returns an error channel. `nil` on it signifies everything was fine, anything else is a serious problem.
func forwardDataFrames(srcStream *transport.Stream, dstStream *transport.Stream, dstTransport transportWriter) chan error {
ret := make(chan error, 1)
go func() {
data := make([]byte, 4096)
opt := &transport.Options{}
for {
n, err := srcStream.Read(data)
if err != nil { // including io.EOF
// Send nil to terminate the stream.
opt.Last = true
dstTransport.Write(dstStream, nil, opt)
ret <- err
break
}
if err := dstTransport.Write(dstStream, data[:n], opt); err != nil {
ret <- err
break
}
}
close(ret)
}()
return ret
}