本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}