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


Golang ReadWriter.ReadInt32方法代碼示例

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


在下文中一共展示了ReadWriter.ReadInt32方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ReadFrom

func (o *ObjectData) ReadFrom(r io.Reader) (n int64, err error) {
	var rw must.ReadWriter

	o.Data = rw.ReadInt32(r)
	if o.Data != 0 {
		o.SpeedX = rw.ReadInt16(r)
		o.SpeedY = rw.ReadInt16(r)
		o.SpeedZ = rw.ReadInt16(r)
	}

	return rw.Result()
}
開發者ID:KellyLSB,項目名稱:minero-go,代碼行數:12,代碼來源:objectdata.go

示例2: ReadFrom

func (re *Region) ReadFrom(r io.Reader) (n int64, err error) {
	var rw must.ReadWriter

	// Copy everything to a buffer. Max size: 4MB + 8KB
	var all bytes.Buffer
	rw.Must(io.Copy(&all, r))

	// Read chunk positions.
	for i := 0; i < len(re.Pos); i++ {
		// Read 4KB offset from file start. Only first 3 bytes needed.
		re.Pos[i] = rw.ReadInt32(&all) >> 8

		// Fourth byte is a 4KB section counter which is ignored because we
		// already know the length of chunk data.
		//
		// More info here:
		// http://www.minecraftwiki.net/wiki/Region_file_format#Structure
		//
		// " The remainder of the file consists of data for up to 1024 chunks,
		// interspersed with an arbitrary amount of unused space. "
		//
		// TLDR: Just another idiotic/bad designed spec.
	}

	// Read chunk timestamps.
	//
	// Last modification time of a chunk. Unit: unknown, seconds?
	//
	// NOTE: Does something use this? MCEdit maybe?
	for i := 0; i < len(re.Mod); i++ {
		re.Mod[i] = rw.ReadInt32(&all)
	}

	// Read chunk data.
	for i := 0; i < len(re.Data); i++ {
		re.Data[i].Length = rw.ReadInt32(&all)
		re.Data[i].Compression = byte(rw.ReadInt8(&all))

		var buf bytes.Buffer
		io.CopyN(&buf, &all, length-1)

		switch scheme {
		case Gzip:
			panic("Alpha chunk format not implemented.")
		case Zlib:
			zr := zlib.NewReader(&all)
			io.Copy(&buf, zr)
		}

		re.Data[i].Chunk = buf.Bytes()
	}

	return rw.Result()
}
開發者ID:KellyLSB,項目名稱:minero-go,代碼行數:54,代碼來源:region.go


注:本文中的github.com/minero/minero/util/must.ReadWriter.ReadInt32方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。