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


Golang binary.Reader類代碼示例

本文整理匯總了Golang中github.com/funny/binary.Reader的典型用法代碼示例。如果您正苦於以下問題:Golang Reader類的具體用法?Golang Reader怎麽用?Golang Reader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: Unmarshal

func (msg *gatewayMsg) Unmarshal(r *binary.Reader) error {
	msg.Command = r.ReadUint8()
	//	DEBUG("收到:" + strconv.Itoa(int(msg.Command)))
	switch msg.Command {
	case CMD_NEW_1:
		msg.ClientId = r.ReadUint64BE()
		msg.Data = r.ReadPacket(binary.SplitByUint8)
	case CMD_NEW_2:
		msg.ClientId = r.ReadUint64BE()
		msg.ClientIds = []uint64{r.ReadUint64BE()}
	case CMD_NEW_3:
		msg.ClientId = r.ReadUint64BE()
	case CMD_DEL:
		msg.ClientId = r.ReadUint64BE()
	case CMD_MSG:
		msg.ClientId = r.ReadUint64BE()
		msg.Data = r.ReadPacket(binary.SplitByUvarint)
	case CMD_BRD:
		num := int(r.ReadUvarint())
		msg.ClientIds = make([]uint64, num)
		for i := 0; i < num; i++ {
			msg.ClientIds[i] = r.ReadUvarint()
		}
		msg.Data = r.ReadPacket(binary.SplitByUvarint)
	}
	return nil
}
開發者ID:youxidev,項目名稱:GoGameServer,代碼行數:27,代碼來源:message.go

示例2: Unmarshal

func (msg *TestMessage) Unmarshal(r *binary.Reader) error {
	*msg = r.ReadPacket(binary.SplitByUvarint)
	return nil
}
開發者ID:youxidev,項目名稱:GoGameServer,代碼行數:4,代碼來源:stream_test.go

示例3: BinaryDecode

func (msg *gatewayMsg) BinaryDecode(r *binary.Reader) error {
	msg.Command = r.ReadUint8()
	switch msg.Command {
	case CMD_NEW_1:
		msg.ClientId = r.ReadUint64BE()
		msg.Data = r.ReadPacket(binary.SplitByUint8)
	case CMD_NEW_2:
		msg.ClientId = r.ReadUint64BE()
		msg.ClientIds = []uint64{r.ReadUint64BE()}
	case CMD_DEL:
		msg.ClientId = r.ReadUint64BE()
	case CMD_MSG:
		msg.ClientId = r.ReadUint64BE()
		msg.Data = r.ReadPacket(binary.SplitByUvarint)
	case CMD_BRD:
		num := int(r.ReadUvarint())
		msg.ClientIds = make([]uint64, num)
		for i := 0; i < num; i++ {
			msg.ClientIds[i] = r.ReadUvarint()
		}
		msg.Data = r.ReadPacket(binary.SplitByUvarint)
	}
	return nil
}
開發者ID:616050468,項目名稱:link,代碼行數:24,代碼來源:message.go

示例4: BinaryDecode

func (obj *TestObject) BinaryDecode(r *binary.Reader) error {
	obj.X = int(r.ReadVarint())
	obj.Y = int(r.ReadVarint())
	obj.Z = int(r.ReadVarint())
	return nil
}
開發者ID:616050468,項目名稱:link,代碼行數:6,代碼來源:session_test.go


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