feat(network)!: add v2 framing, pooled buffers and bounded dispatch
This commit is contained in:
@@ -9,6 +9,8 @@ namespace ShrinkNetwork
|
||||
{
|
||||
private readonly Dictionary<int, ShrinkNetworkMessageMeta> _opcodeToMeta = new();
|
||||
private readonly Dictionary<Type, ShrinkNetworkMessageMeta> _typeToMeta = new();
|
||||
private readonly HashSet<string> _routes = new(StringComparer.Ordinal);
|
||||
public IReadOnlyCollection<ShrinkNetworkMessageMeta> Registrations => _typeToMeta.Values;
|
||||
|
||||
public void Register<TMessage>(int opcode, string? route = null) where TMessage : IShrinkNetworkMessage
|
||||
=> Register(typeof(TMessage), opcode, route);
|
||||
@@ -24,6 +26,8 @@ namespace ShrinkNetwork
|
||||
if (_typeToMeta.ContainsKey(messageType))
|
||||
throw new InvalidOperationException($"Message type {messageType.FullName} is already registered.");
|
||||
|
||||
route = string.IsNullOrWhiteSpace(route) ? null : route.Trim();
|
||||
if (route != null && !_routes.Add(route)) throw new InvalidOperationException($"SHRINK002 Route '{route}' is already registered.");
|
||||
var meta = new ShrinkNetworkMessageMeta(opcode, messageType, route);
|
||||
_opcodeToMeta.Add(opcode, meta);
|
||||
_typeToMeta.Add(messageType, meta);
|
||||
|
||||
Reference in New Issue
Block a user