Files
arpack/benchmarks/arpackmsg/messages_gen.go
T

222 lines
6.3 KiB
Go
Raw Normal View History

2026-03-23 12:52:30 +03:00
// Code generated by arpack. DO NOT EDIT.
package arpackmsg
import (
"encoding/binary"
"errors"
"math"
)
func (m *Vector3) Marshal(buf []byte) []byte {
_qm_X := uint16((m.X - (-500)) / (500 - (-500)) * 65535)
buf = binary.LittleEndian.AppendUint16(buf, _qm_X)
_qm_Y := uint16((m.Y - (-500)) / (500 - (-500)) * 65535)
buf = binary.LittleEndian.AppendUint16(buf, _qm_Y)
_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, uint16(len(m.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, uint16(len(m.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, uint16(len(m.Tags)))
for _iTags := range m.Tags {
buf = binary.LittleEndian.AppendUint16(buf, uint16(len(m.Tags[_iTags])))
buf = append(buf, m.Tags[_iTags]...)
}
buf = binary.LittleEndian.AppendUint16(buf, uint16(len(m.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
}