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


Golang packet.WriteUint16函數代碼示例

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


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

示例1: Encode

func (this *PacketResultCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetResult := encode.(*PacketResult)
	err = packet.WriteInt32(writer, util, packetResult.SequenceId)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, util, packetResult.StatusCode)
	if packetResult.StatusCode == STATUS_SUCCESS {
		if packetResult.Result.Id() < 0 {
			err = errors.New(fmt.Sprintf("Encode, Request Id is below zero: %d", packetResult.Result.Id()))
			return
		}
		if packetResult.Result.Id() >= len(requestCodecs) {
			err = errors.New(fmt.Sprintf("Encode, Request Id is above maximum: %d", packetResult.Result.Id()))
			return
		}
		buffer := &bytes.Buffer{}
		codec := resultCodecs[packetResult.Result.Id()]
		if codec == nil {
			err = errors.New(fmt.Sprintf("Encode, Request Id does not have a codec: %d", packetResult.Result.Id()))
			return
		}
		err = codec.Encode(buffer, util, packetResult.Result)
		if err != nil {
			return
		}
		payload := buffer.Bytes()
		err = packet.WriteUint16(writer, util, uint16(len(payload)))
		if err != nil {
			return
		}
		_, err = writer.Write(payload)
	}
	return
}
開發者ID:Jumla,項目名稱:GoLilyPad,代碼行數:35,代碼來源:packetResult.go

示例2: Encode

func (this *packetServerLoginEncryptResponseCodec17) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetServerLoginEncryptResponse := encode.(*PacketServerLoginEncryptResponse)
	err = packet.WriteUint16(writer, uint16(len(packetServerLoginEncryptResponse.SharedSecret)))
	if err != nil {
		return
	}
	_, err = writer.Write(packetServerLoginEncryptResponse.SharedSecret)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, uint16(len(packetServerLoginEncryptResponse.VerifyToken)))
	if err != nil {
		return
	}
	_, err = writer.Write(packetServerLoginEncryptResponse.VerifyToken)
	return
}
開發者ID:0xNiklas,項目名稱:GoLilyPad,代碼行數:17,代碼來源:packetServerLoginEncryptResponse17.go

示例3: Encode

func (this *RequestAsServerCodec) Encode(writer io.Writer, util []byte, request Request) (err error) {
	requestAsServer := request.(*RequestAsServer)
	err = packet.WriteString(writer, util, requestAsServer.Address)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, requestAsServer.Port)
	return
}
開發者ID:Jumla,項目名稱:GoLilyPad,代碼行數:9,代碼來源:requestAsServer.go

示例4: Encode

func (this *packetClientLoginEncryptRequestCodec17) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientLoginEncryptRequest := encode.(*PacketClientLoginEncryptRequest)
	err = packet.WriteString(writer, util, packetClientLoginEncryptRequest.ServerId)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, uint16(len(packetClientLoginEncryptRequest.PublicKey)))
	if err != nil {
		return
	}
	_, err = writer.Write(packetClientLoginEncryptRequest.PublicKey)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, uint16(len(packetClientLoginEncryptRequest.VerifyToken)))
	if err != nil {
		return
	}
	_, err = writer.Write(packetClientLoginEncryptRequest.VerifyToken)
	return
}
開發者ID:LivousCraftNetwork,項目名稱:GoLilyPad,代碼行數:21,代碼來源:packetClientLoginEncryptRequest17.go

示例5: Encode

func (this *requestAsProxyCodec) Encode(writer io.Writer, util []byte, request Request) (err error) {
	requestAsProxy := request.(*RequestAsProxy)
	err = packet.WriteString(writer, util, requestAsProxy.Address)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, requestAsProxy.Port)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, requestAsProxy.Motd)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, requestAsProxy.Version)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, requestAsProxy.MaxPlayers)
	return
}
開發者ID:LivousCraftNetwork,項目名稱:GoLilyPad,代碼行數:21,代碼來源:requestAsProxy.go

示例6: Encode

func (this *resultGetPlayersCodec) Encode(writer io.Writer, result Result) (err error) {
	resultGetPlayers := result.(*ResultGetPlayers)
	err = packet.WriteBool(writer, resultGetPlayers.List)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, resultGetPlayers.CurrentPlayers)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, resultGetPlayers.MaxPlayers)
	if resultGetPlayers.List {
		var i uint16
		for i = 0; i < resultGetPlayers.CurrentPlayers; i++ {
			if err != nil {
				return
			}
			err = packet.WriteString(writer, resultGetPlayers.Players[i])
		}
	}
	return
}
開發者ID:0xNiklas,項目名稱:GoLilyPad,代碼行數:22,代碼來源:requestGetPlayers.go

示例7: Encode

func (this *packetServerPluginMessageCodec17) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetServerPluginMessage := encode.(*PacketServerPluginMessage)
	err = packet.WriteString(writer, util, packetServerPluginMessage.Channel)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, uint16(len(packetServerPluginMessage.Data)))
	if err != nil {
		return
	}
	_, err = writer.Write(packetServerPluginMessage.Data)
	return
}
開發者ID:LivousCraftNetwork,項目名稱:GoLilyPad,代碼行數:13,代碼來源:packetServerPluginMessage17.go

示例8: Encode

func (this *requestMessageCodec) Encode(writer io.Writer, request Request) (err error) {
	requestMessage := request.(*RequestMessage)
	err = packet.WriteUint16(writer, uint16(len(requestMessage.Recipients)))
	for i := 0; i < len(requestMessage.Recipients); i++ {
		if err != nil {
			return
		}
		err = packet.WriteString(writer, requestMessage.Recipients[i])
	}
	if err != nil {
		return
	}
	err = packet.WriteString(writer, requestMessage.Channel)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, uint16(len(requestMessage.Message)))
	if err != nil {
		return
	}
	_, err = writer.Write(requestMessage.Message)
	return
}
開發者ID:0xNiklas,項目名稱:GoLilyPad,代碼行數:23,代碼來源:requestMessage.go

示例9: Encode

func (this *packetMessageEventCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetMessageEvent := encode.(*PacketMessageEvent)
	err = packet.WriteString(writer, packetMessageEvent.Sender)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, packetMessageEvent.Channel)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, uint16(len(packetMessageEvent.Payload)))
	if err != nil {
		return
	}
	_, err = writer.Write(packetMessageEvent.Payload)
	return
}
開發者ID:0xNiklas,項目名稱:GoLilyPad,代碼行數:17,代碼來源:packetMessageEvent.go

示例10: Encode

func (this *PacketServerHandshakeCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetServerHandshake := encode.(*PacketServerHandshake)
	err = packet.WriteVarInt(writer, util, packetServerHandshake.ProtocolVersion)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, util, packetServerHandshake.ServerAddress)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, util, packetServerHandshake.ServerPort)
	if err != nil {
		return
	}
	err = packet.WriteVarInt(writer, util, packetServerHandshake.State)
	return
}
開發者ID:Jumla,項目名稱:GoLilyPad,代碼行數:17,代碼來源:packetServerHandshake.go

示例11: Encode

func (this *resultGetDetailsCodec) Encode(writer io.Writer, result Result) (err error) {
	resultGetDetails := result.(*ResultGetDetails)
	err = packet.WriteString(writer, resultGetDetails.Ip)
	if err != nil {
		return
	}
	err = packet.WriteUint16(writer, resultGetDetails.Port)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, resultGetDetails.Motd)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, resultGetDetails.Version)
	return
}
開發者ID:0xNiklas,項目名稱:GoLilyPad,代碼行數:17,代碼來源:requestGetDetails.go

示例12: Encode

func (this *PacketClientTeamsCodec) Encode(writer io.Writer, util []byte, encode packet.Packet) (err error) {
	packetClientTeams := encode.(*PacketClientTeams)
	err = packet.WriteString(writer, util, packetClientTeams.Name)
	if err != nil {
		return
	}
	err = packet.WriteInt8(writer, util, packetClientTeams.Action)
	if packetClientTeams.Action == 0 || packetClientTeams.Action == 2 {
		if err != nil {
			return
		}
		err = packet.WriteString(writer, util, packetClientTeams.DisplayName)
		if err != nil {
			return
		}
		err = packet.WriteString(writer, util, packetClientTeams.Prefix)
		if err != nil {
			return
		}
		err = packet.WriteString(writer, util, packetClientTeams.Suffix)
		if err != nil {
			return
		}
		err = packet.WriteInt8(writer, util, packetClientTeams.FriendlyFire)
	}
	if packetClientTeams.Action == 0 || packetClientTeams.Action == 3 || packetClientTeams.Action == 4 {
		if err != nil {
			return
		}
		err = packet.WriteUint16(writer, util, uint16(len(packetClientTeams.Players)))
		for i := 0; i < len(packetClientTeams.Players); i++ {
			if err != nil {
				return
			}
			err = packet.WriteString(writer, util, packetClientTeams.Players[i])
		}
	}
	return
}
開發者ID:Jumla,項目名稱:GoLilyPad,代碼行數:39,代碼來源:packetClientTeams.go

示例13: Encode

func (this *packetServerEventCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetServerEvent := encode.(*PacketServerEvent)
	err = packet.WriteBool(writer, packetServerEvent.Add)
	if err != nil {
		return
	}
	err = packet.WriteString(writer, packetServerEvent.Server)
	if packetServerEvent.Add {
		if err != nil {
			return
		}
		err = packet.WriteString(writer, packetServerEvent.SecurityKey)
		if err != nil {
			return
		}
		err = packet.WriteString(writer, packetServerEvent.Address)
		if err != nil {
			return
		}
		err = packet.WriteUint16(writer, packetServerEvent.Port)
	}
	return
}
開發者ID:0xNiklas,項目名稱:GoLilyPad,代碼行數:23,代碼來源:packetServerEvent.go

示例14: Encode

func (this *packetRequestCodec) Encode(writer io.Writer, encode packet.Packet) (err error) {
	packetRequest := encode.(*PacketRequest)
	err = packet.WriteInt32(writer, packetRequest.SequenceId)
	if err != nil {
		return
	}
	err = packet.WriteUint8(writer, uint8(packetRequest.Request.Id()))
	if err != nil {
		return
	}
	if packetRequest.Request.Id() < 0 {
		err = errors.New(fmt.Sprintf("Encode, Request Id is below zero: %d", packetRequest.Request.Id()))
		return
	}
	if packetRequest.Request.Id() >= len(requestCodecs) {
		err = errors.New(fmt.Sprintf("Encode, Request Id is above maximum: %d", packetRequest.Request.Id()))
		return
	}
	buffer := new(bytes.Buffer)
	codec := requestCodecs[packetRequest.Request.Id()]
	if codec == nil {
		err = errors.New(fmt.Sprintf("Encode, Request Id does not have a codec: %d", packetRequest.Request.Id()))
		return
	}
	err = codec.Encode(buffer, packetRequest.Request)
	if err != nil {
		return
	}
	payload := buffer.Bytes()
	err = packet.WriteUint16(writer, uint16(len(payload)))
	if err != nil {
		return
	}
	_, err = writer.Write(payload)
	return
}
開發者ID:0xNiklas,項目名稱:GoLilyPad,代碼行數:36,代碼來源:packetRequest.go


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