perf(net): borrow inbound packet storage
Decode headers, optional fields, fragments, and single-fragment messages directly over pooled datagrams. Copy only fragment state that crosses a datagram lifetime, preserve synchronous dispatch and ACK ordering, and lock the path to the owned decoder with differential and zero-allocation tests.
This commit is contained in:
parent
7211bb1bf7
commit
e928c5dd02
18 changed files with 1329 additions and 66 deletions
|
|
@ -32,9 +32,9 @@ public static class ServerMessage
|
|||
|
||||
public readonly record struct Parsed(string Message, uint ChatType);
|
||||
|
||||
public static Parsed? TryParse(byte[] body)
|
||||
public static Parsed? TryParse(ReadOnlySpan<byte> body)
|
||||
{
|
||||
if (body is null || body.Length < 8) return null;
|
||||
if (body.Length < 8) return null;
|
||||
uint opcode = BinaryPrimitives.ReadUInt32LittleEndian(body);
|
||||
if (opcode != Opcode) return null;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ public static class ServerMessage
|
|||
int pos = 4;
|
||||
string message = StringReader.ReadString16L(body, ref pos);
|
||||
if (body.Length - pos < 4) return null;
|
||||
uint chatType = BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(pos));
|
||||
uint chatType = BinaryPrimitives.ReadUInt32LittleEndian(body.Slice(pos));
|
||||
return new Parsed(message, chatType);
|
||||
}
|
||||
catch { return null; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue