Table of Contents

Class BaseGameNetworkPacket

Namespace
Moongate.Network.Packets.Base
Assembly
Moongate.Network.Packets.dll

Base implementation for game network packets with shared opcode and parsing validation logic.

public abstract class BaseGameNetworkPacket : IGameNetworkPacket
Inheritance
BaseGameNetworkPacket
Implements
Derived
Inherited Members

Constructors

BaseGameNetworkPacket(byte, int)

Initializes a new packet base with opcode and expected length.

protected BaseGameNetworkPacket(byte opCode, int length = -1)

Parameters

opCode byte

Packet opcode.

length int

Expected packet length, or -1 for variable length.

Properties

Length

Gets the packet length. Use -1 for variable-length packets.

public int Length { get; }

Property Value

int

OpCode

Gets the packet opcode identifier.

public byte OpCode { get; }

Property Value

byte

Methods

ParsePayload(ref SpanReader)

Parses packet-specific payload after opcode validation.

protected abstract bool ParsePayload(ref SpanReader reader)

Parameters

reader SpanReader

Packet span reader positioned after opcode.

Returns

bool

true when payload parsing succeeds; otherwise false.

TryParse(ReadOnlySpan<byte>)

Tries to parse packet bytes after validating opcode and optional fixed length.

public bool TryParse(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

Raw packet bytes.

Returns

bool

true when parsing succeeds; otherwise false.

Write(ref SpanWriter)

Writes packet content to the target span writer.

public virtual void Write(ref SpanWriter writer)

Parameters

writer SpanWriter

Destination writer.