Skip to content

Commit

Permalink
perf[cs]: get protocolId by class type
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Jan 25, 2024
1 parent a23d5d1 commit 61eea44
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions protocol/src/main/resources/csharp/ProtocolManagerTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ public static void InitProtocol()
{}
}

public static short GetProtocolId(Type type)
{
return protocolIdMap[type];
}

public static IProtocolRegistration GetProtocol(short protocolId)
{
var protocol = protocols[protocolId];
if (protocol == null)
{
throw new Exception("[protocolId:" + protocolId + "] not exist");
}

return protocol;
}

Expand All @@ -39,7 +43,6 @@ public static void Write(ByteBuffer buffer, object packet)
var protocolId = protocolIdMap[packet.GetType()];
// 写入协议号
buffer.WriteShort(protocolId);

// 写入包体
GetProtocol(protocolId).Write(buffer, packet);
}
Expand Down

0 comments on commit 61eea44

Please sign in to comment.