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.
55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System;
|
|
using System.Buffers.Binary;
|
|
|
|
namespace AcDream.Core.Net.Messages;
|
|
|
|
/// <summary>
|
|
/// Inbound <c>0x01E0 EmoteText</c> top-level GameMessage.
|
|
/// Server-driven third-person emote announcement (e.g.
|
|
/// "The Olthoi growls at you.").
|
|
///
|
|
/// <para>
|
|
/// This is a standalone GameMessage — NOT wrapped in the 0xF7B0
|
|
/// GameEvent envelope. Dispatched directly from the opcode switch in
|
|
/// <see cref="WorldSession.ProcessDatagram"/>.
|
|
/// </para>
|
|
///
|
|
/// <para>
|
|
/// Wire layout (port from holtburger
|
|
/// <c>references/holtburger/.../messages/chat/types.rs::EmoteTextData</c>,
|
|
/// see also opcodes.rs:155):
|
|
/// <code>
|
|
/// u32 opcode // 0x01E0
|
|
/// u32 senderGuid
|
|
/// string16L senderName
|
|
/// string16L text
|
|
/// </code>
|
|
/// </para>
|
|
/// </summary>
|
|
public static class EmoteText
|
|
{
|
|
public const uint Opcode = 0x01E0u;
|
|
|
|
public readonly record struct Parsed(
|
|
uint SenderGuid,
|
|
string SenderName,
|
|
string Text);
|
|
|
|
public static Parsed? TryParse(ReadOnlySpan<byte> body)
|
|
{
|
|
if (body.Length < 8) return null;
|
|
uint opcode = BinaryPrimitives.ReadUInt32LittleEndian(body);
|
|
if (opcode != Opcode) return null;
|
|
|
|
try
|
|
{
|
|
int pos = 4;
|
|
uint senderGuid = BinaryPrimitives.ReadUInt32LittleEndian(body.Slice(pos));
|
|
pos += 4;
|
|
string senderName = StringReader.ReadString16L(body, ref pos);
|
|
string text = StringReader.ReadString16L(body, ref pos);
|
|
return new Parsed(senderGuid, senderName, text);
|
|
}
|
|
catch { return null; }
|
|
}
|
|
}
|