Class BaseGameNetworkPacket
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
Properties
Length
Gets the packet length. Use -1 for variable-length packets.
public int Length { get; }
Property Value
OpCode
Gets the packet opcode identifier.
public byte OpCode { get; }
Property Value
Methods
ParsePayload(ref SpanReader)
Parses packet-specific payload after opcode validation.
protected abstract bool ParsePayload(ref SpanReader reader)
Parameters
readerSpanReaderPacket span reader positioned after opcode.
Returns
- bool
truewhen payload parsing succeeds; otherwisefalse.
TryParse(ReadOnlySpan<byte>)
Tries to parse packet bytes after validating opcode and optional fixed length.
public bool TryParse(ReadOnlySpan<byte> data)
Parameters
dataReadOnlySpan<byte>Raw packet bytes.
Returns
- bool
truewhen parsing succeeds; otherwisefalse.
Write(ref SpanWriter)
Writes packet content to the target span writer.
public virtual void Write(ref SpanWriter writer)
Parameters
writerSpanWriterDestination writer.