本文整理匯總了Golang中github.com/minero/minero/util/must.ReadWriter.Check方法的典型用法代碼示例。如果您正苦於以下問題:Golang ReadWriter.Check方法的具體用法?Golang ReadWriter.Check怎麽用?Golang ReadWriter.Check使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/minero/minero/util/must.ReadWriter
的用法示例。
在下文中一共展示了ReadWriter.Check方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WriteTo
func (s *Slot) WriteTo(w io.Writer) (n int64, err error) {
var rw must.ReadWriter
rw.WriteInt16(w, s.BlockId)
if s.BlockId == -1 {
return rw.Result()
}
rw.WriteInt8(w, int8(s.Amount))
rw.WriteInt16(w, s.Damage)
if s.Enchantments == nil {
rw.WriteInt16(w, -1)
return rw.Result()
}
var bn, bw bytes.Buffer
rw.Check(nbt.Write(&bn, s.Enchantments))
gw := gzip.NewWriter(&bw)
rw.Must(io.Copy(gw, &bn))
rw.Check(gw.Close())
rw.WriteInt16(w, int16(bw.Len()))
rw.WriteByteArray(w, bw.Bytes())
return rw.Result()
}
示例2: WriteTo
func (m Metadata) WriteTo(w io.Writer) (n int64, err error) {
var rw must.ReadWriter
var buf bytes.Buffer
for index, payload := range m.Entries {
buf.Reset()
typ := payload.Type()
rw.Check(buf.WriteByte(typ<<5 | (index & 0x1F)))
// Write type+key & payload
rw.Must(buf.WriteTo(w))
rw.Must(payload.WriteTo(w))
}
buf.Reset()
rw.Check(buf.WriteByte(0x7f))
rw.Must(buf.WriteTo(w))
return rw.Result()
}
示例3: ReadFrom
func (s *Slot) ReadFrom(r io.Reader) (n int64, err error) {
var rw must.ReadWriter
s.BlockId = rw.ReadInt16(r)
if s.BlockId == -1 {
return rw.Result()
}
s.Amount = byte(rw.ReadInt8(r))
s.Damage = rw.ReadInt16(r)
Length := rw.ReadInt16(r)
if Length == -1 {
return rw.Result()
}
var br bytes.Buffer
// Copy gzip'd NBT Compound
gs := rw.ReadByteArray(r, int(Length))
bn := bytes.NewBuffer(gs)
// Ungzip byte array
gr, err := gzip.NewReader(bn)
rw.Check(err)
rw.Must(io.Copy(&br, gr))
rw.Check(gr.Close())
// Read NBT Compound
s.Enchantments, err = nbt.Read(&br)
rw.Check(err)
return rw.Result()
}