本文整理汇总了Golang中github.com/calmh/xdr.Writer.WriteRaw方法的典型用法代码示例。如果您正苦于以下问题:Golang Writer.WriteRaw方法的具体用法?Golang Writer.WriteRaw怎么用?Golang Writer.WriteRaw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/calmh/xdr.Writer
的用法示例。
在下文中一共展示了Writer.WriteRaw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: timeoutWriteHeader
func timeoutWriteHeader(w *xdr.Writer, hdr header) {
// This tries to write a message header to w, but times out after a while.
// This is useful because in testing, with a PipeWriter, it will block
// forever if the other side isn't reading any more. On the other hand we
// can't just "go" it into the background, because if the other side is
// still there we should wait for the write to complete. Yay.
var buf [8]byte // header and message length
binary.BigEndian.PutUint32(buf[:], encodeHeader(hdr))
binary.BigEndian.PutUint32(buf[4:], 0) // zero message length, explicitly
done := make(chan struct{})
go func() {
w.WriteRaw(buf[:])
l.Infoln("write completed")
close(done)
}()
select {
case <-done:
case <-time.After(250 * time.Millisecond):
}
}
示例2: encodeXDR
func (u *Opaque) encodeXDR(w *xdr.Writer) (int, error) {
return w.WriteRaw(u[:])
}