238 lines
7.1 KiB
Go
238 lines
7.1 KiB
Go
// Code generated by arpack. DO NOT EDIT.
|
|
|
|
package arpackmsg
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"errors"
|
|
"math"
|
|
)
|
|
|
|
func arpackEnsureUint16Length(length int, context string) uint16 {
|
|
if length > 65535 {
|
|
panic("arpack: " + context + " exceeds uint16 limit")
|
|
}
|
|
return uint16(length)
|
|
}
|
|
|
|
func arpackEnsureQuantizedRange(value float64, min float64, max float64, context string) {
|
|
if value != value || value < min || value > max {
|
|
panic("arpack: quantized value out of range for " + context)
|
|
}
|
|
}
|
|
|
|
func (m *Vector3) Marshal(buf []byte) []byte {
|
|
arpackEnsureQuantizedRange(float64(m.X), -500, 500, "X")
|
|
_qm_X := uint16((m.X - (-500)) / (500 - (-500)) * 65535)
|
|
buf = binary.LittleEndian.AppendUint16(buf, _qm_X)
|
|
arpackEnsureQuantizedRange(float64(m.Y), -500, 500, "Y")
|
|
_qm_Y := uint16((m.Y - (-500)) / (500 - (-500)) * 65535)
|
|
buf = binary.LittleEndian.AppendUint16(buf, _qm_Y)
|
|
arpackEnsureQuantizedRange(float64(m.Z), -500, 500, "Z")
|
|
_qm_Z := uint16((m.Z - (-500)) / (500 - (-500)) * 65535)
|
|
buf = binary.LittleEndian.AppendUint16(buf, _qm_Z)
|
|
return buf
|
|
}
|
|
|
|
func (m *Vector3) Unmarshal(data []byte) (int, error) {
|
|
if len(data) < 6 {
|
|
return 0, errors.New("arpack: buffer too short for Vector3")
|
|
}
|
|
offset := 0
|
|
if len(data) < offset+2 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
_qm_X := binary.LittleEndian.Uint16(data[offset:])
|
|
offset += 2
|
|
m.X = float32(_qm_X)/65535*(500-(-500)) + (-500)
|
|
if len(data) < offset+2 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
_qm_Y := binary.LittleEndian.Uint16(data[offset:])
|
|
offset += 2
|
|
m.Y = float32(_qm_Y)/65535*(500-(-500)) + (-500)
|
|
if len(data) < offset+2 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
_qm_Z := binary.LittleEndian.Uint16(data[offset:])
|
|
offset += 2
|
|
m.Z = float32(_qm_Z)/65535*(500-(-500)) + (-500)
|
|
return offset, nil
|
|
}
|
|
|
|
func (m *MoveMessage) Marshal(buf []byte) []byte {
|
|
buf = m.Position.Marshal(buf)
|
|
for _iVelocity := 0; _iVelocity < 3; _iVelocity++ {
|
|
buf = binary.LittleEndian.AppendUint32(buf, math.Float32bits(m.Velocity[_iVelocity]))
|
|
}
|
|
buf = binary.LittleEndian.AppendUint16(buf, arpackEnsureUint16Length(len(m.Waypoints), "slice length for Waypoints"))
|
|
for _iWaypoints := range m.Waypoints {
|
|
buf = m.Waypoints[_iWaypoints].Marshal(buf)
|
|
}
|
|
buf = binary.LittleEndian.AppendUint32(buf, m.PlayerID)
|
|
var _boolByte4 uint8
|
|
if m.Active {
|
|
_boolByte4 |= 1 << 0
|
|
}
|
|
if m.Visible {
|
|
_boolByte4 |= 1 << 1
|
|
}
|
|
if m.Ghost {
|
|
_boolByte4 |= 1 << 2
|
|
}
|
|
buf = append(buf, _boolByte4)
|
|
buf = binary.LittleEndian.AppendUint16(buf, arpackEnsureUint16Length(len(m.Name), "string length for Name"))
|
|
buf = append(buf, m.Name...)
|
|
return buf
|
|
}
|
|
|
|
func (m *MoveMessage) Unmarshal(data []byte) (int, error) {
|
|
if len(data) < 23 {
|
|
return 0, errors.New("arpack: buffer too short for MoveMessage")
|
|
}
|
|
offset := 0
|
|
_nPosition, _err := m.Position.Unmarshal(data[offset:])
|
|
if _err != nil {
|
|
return 0, _err
|
|
}
|
|
offset += _nPosition
|
|
for _iVelocity := 0; _iVelocity < 3; _iVelocity++ {
|
|
if len(data) < offset+4 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
m.Velocity[_iVelocity] = math.Float32frombits(binary.LittleEndian.Uint32(data[offset:]))
|
|
offset += 4
|
|
}
|
|
if len(data) < offset+2 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
_lenWaypoints := int(binary.LittleEndian.Uint16(data[offset:]))
|
|
offset += 2
|
|
m.Waypoints = make([]Vector3, _lenWaypoints)
|
|
for _iWaypoints := 0; _iWaypoints < _lenWaypoints; _iWaypoints++ {
|
|
_nWaypoints__iWaypoints_, _err := m.Waypoints[_iWaypoints].Unmarshal(data[offset:])
|
|
if _err != nil {
|
|
return 0, _err
|
|
}
|
|
offset += _nWaypoints__iWaypoints_
|
|
}
|
|
if len(data) < offset+4 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
m.PlayerID = binary.LittleEndian.Uint32(data[offset:])
|
|
offset += 4
|
|
if len(data) < offset+1 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
_boolByte4 := data[offset]
|
|
offset++
|
|
m.Active = _boolByte4&(1<<0) != 0
|
|
m.Visible = _boolByte4&(1<<1) != 0
|
|
m.Ghost = _boolByte4&(1<<2) != 0
|
|
if len(data) < offset+2 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
_slenm_Name := int(binary.LittleEndian.Uint16(data[offset:]))
|
|
offset += 2
|
|
if len(data) < offset+_slenm_Name {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
m.Name = string(data[offset : offset+_slenm_Name])
|
|
offset += _slenm_Name
|
|
return offset, nil
|
|
}
|
|
|
|
func (m *SpawnMessage) Marshal(buf []byte) []byte {
|
|
buf = binary.LittleEndian.AppendUint64(buf, m.EntityID)
|
|
buf = m.Position.Marshal(buf)
|
|
buf = binary.LittleEndian.AppendUint16(buf, uint16(m.Health))
|
|
buf = binary.LittleEndian.AppendUint16(buf, arpackEnsureUint16Length(len(m.Tags), "slice length for Tags"))
|
|
for _iTags := range m.Tags {
|
|
buf = binary.LittleEndian.AppendUint16(buf, arpackEnsureUint16Length(len(m.Tags[_iTags]), "string length for Tags[_iTags]"))
|
|
buf = append(buf, m.Tags[_iTags]...)
|
|
}
|
|
buf = binary.LittleEndian.AppendUint16(buf, arpackEnsureUint16Length(len(m.Data), "slice length for Data"))
|
|
for _iData := range m.Data {
|
|
buf = append(buf, m.Data[_iData])
|
|
}
|
|
return buf
|
|
}
|
|
|
|
func (m *SpawnMessage) Unmarshal(data []byte) (int, error) {
|
|
if len(data) < 16 {
|
|
return 0, errors.New("arpack: buffer too short for SpawnMessage")
|
|
}
|
|
offset := 0
|
|
if len(data) < offset+8 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
m.EntityID = binary.LittleEndian.Uint64(data[offset:])
|
|
offset += 8
|
|
_nPosition, _err := m.Position.Unmarshal(data[offset:])
|
|
if _err != nil {
|
|
return 0, _err
|
|
}
|
|
offset += _nPosition
|
|
if len(data) < offset+2 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
m.Health = int16(binary.LittleEndian.Uint16(data[offset:]))
|
|
offset += 2
|
|
if len(data) < offset+2 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
_lenTags := int(binary.LittleEndian.Uint16(data[offset:]))
|
|
offset += 2
|
|
m.Tags = make([]string, _lenTags)
|
|
for _iTags := 0; _iTags < _lenTags; _iTags++ {
|
|
if len(data) < offset+2 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
_slenm_Tags__iTags_ := int(binary.LittleEndian.Uint16(data[offset:]))
|
|
offset += 2
|
|
if len(data) < offset+_slenm_Tags__iTags_ {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
m.Tags[_iTags] = string(data[offset : offset+_slenm_Tags__iTags_])
|
|
offset += _slenm_Tags__iTags_
|
|
}
|
|
if len(data) < offset+2 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
_lenData := int(binary.LittleEndian.Uint16(data[offset:]))
|
|
offset += 2
|
|
m.Data = make([]uint8, _lenData)
|
|
for _iData := 0; _iData < _lenData; _iData++ {
|
|
if len(data) < offset+1 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
m.Data[_iData] = data[offset]
|
|
offset += 1
|
|
}
|
|
return offset, nil
|
|
}
|
|
|
|
func (m *EnvelopeMessage) Marshal(buf []byte) []byte {
|
|
buf = binary.LittleEndian.AppendUint16(buf, uint16(m.Code))
|
|
buf = append(buf, m.Counter)
|
|
return buf
|
|
}
|
|
|
|
func (m *EnvelopeMessage) Unmarshal(data []byte) (int, error) {
|
|
if len(data) < 3 {
|
|
return 0, errors.New("arpack: buffer too short for EnvelopeMessage")
|
|
}
|
|
offset := 0
|
|
if len(data) < offset+2 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
m.Code = Opcode(binary.LittleEndian.Uint16(data[offset:]))
|
|
offset += 2
|
|
if len(data) < offset+1 {
|
|
return 0, errors.New("arpack: buffer too short")
|
|
}
|
|
m.Counter = data[offset]
|
|
offset += 1
|
|
return offset, nil
|
|
}
|