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


Golang binary.Writer類代碼示例

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


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

示例1: Marshal

func (msg *gatewayMsg) Marshal(w *binary.Writer) error {
	w.WriteUint8(msg.Command)
	//	DEBUG("發送:" + strconv.Itoa(int(msg.Command)))
	switch msg.Command {
	case CMD_NEW_1:
		w.WriteUint64BE(msg.ClientId)
		w.WritePacket(msg.Data, binary.SplitByUint8)
	case CMD_NEW_2:
		w.WriteUint64BE(msg.ClientId)
		w.WriteUint64BE(msg.ClientIds[0])
	case CMD_NEW_3:
		w.WriteUint64BE(msg.ClientId)
	case CMD_DEL:
		w.WriteUint64BE(msg.ClientId)
	case CMD_MSG:
		w.WriteUint64BE(msg.ClientId)
		goto ENCODE
	case CMD_BRD:
		w.WriteUvarint(uint64(len(msg.ClientIds)))
		for i := 0; i < len(msg.ClientIds); i++ {
			w.WriteUvarint(msg.ClientIds[i])
		}
		goto ENCODE
	}
	return w.Flush()
ENCODE:
	if fast, ok := msg.Message.(packet.FastOutMessage); ok {
		binary.SplitByUvarint.WriteHead(w, fast.MarshalSize())
		if err := fast.Marshal(w); err != nil {
			return err
		}
	} else {
		data, err := msg.Message.(packet.OutMessage).Marshal()
		if err != nil {
			return err
		}
		w.WritePacket(data, binary.SplitByUvarint)
	}
	return w.Flush()
}
開發者ID:youxidev,項目名稱:GoGameServer,代碼行數:40,代碼來源:message.go

示例2: BinaryEncode

func (msg *gatewayMsg) BinaryEncode(w *binary.Writer) error {
	w.WriteUint8(msg.Command)
	switch msg.Command {
	case CMD_NEW_1:
		w.WriteUint64BE(msg.ClientId)
		w.WritePacket(msg.Data, binary.SplitByUint8)
	case CMD_NEW_2:
		w.WriteUint64BE(msg.ClientId)
		w.WriteUint64BE(msg.ClientIds[0])
	case CMD_DEL:
		w.WriteUint64BE(msg.ClientId)
	case CMD_MSG:
		w.WriteUint64BE(msg.ClientId)
		w.WritePacket(msg.Data, binary.SplitByUvarint)
	case CMD_BRD:
		w.WriteUvarint(uint64(len(msg.ClientIds)))
		for i := 0; i < len(msg.ClientIds); i++ {
			w.WriteUvarint(msg.ClientIds[i])
		}
		w.WritePacket(msg.Data, binary.SplitByUvarint)
	}
	return nil
}
開發者ID:616050468,項目名稱:link,代碼行數:23,代碼來源:message.go

示例3: BinaryEncode

func (obj *TestObject) BinaryEncode(w *binary.Writer) error {
	w.WriteVarint(int64(obj.X))
	w.WriteVarint(int64(obj.Y))
	w.WriteVarint(int64(obj.Z))
	return nil
}
開發者ID:616050468,項目名稱:link,代碼行數:6,代碼來源:session_test.go

示例4: Marshal

func (msg TestMessage) Marshal(w *binary.Writer) error {
	w.WritePacket(msg, binary.SplitByUvarint)
	return nil
}
開發者ID:youxidev,項目名稱:GoGameServer,代碼行數:4,代碼來源:stream_test.go

示例5: Marshal

func (msg RAW) Marshal(w *binary.Writer) error {
	_, err := w.Write(msg)
	return err
}
開發者ID:youxidev,項目名稱:GoGameServer,代碼行數:4,代碼來源:api.go


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