perf[protocol]: import IByteBuffer

This commit is contained in:
godotg
2023-12-13 16:22:01 +08:00
parent bb96108784
commit 7354019db1
2 changed files with 6 additions and 4 deletions
@@ -1,4 +1,5 @@
{}
import IByteBuffer from "./IByteBuffer";
const protocols = new Map<number, any>();
@@ -14,14 +15,14 @@ class ProtocolManager {
return protocol;
}
static write(buffer: any, packet: any): void {
static write(buffer: IByteBuffer, packet: any): void {
const protocolId = packet.protocolId();
buffer.writeShort(protocolId);
const protocol = ProtocolManager.getProtocol(protocolId);
protocol.write(buffer, packet);
}
static read(buffer: any): any {
static read(buffer: IByteBuffer): any {
const protocolId = buffer.readShort();
const protocol = ProtocolManager.getProtocol(protocolId);
const packet = protocol.read(buffer);
@@ -5,6 +5,7 @@ import NormalObject from './packet/NormalObject';
import ObjectA from './packet/ObjectA';
import ObjectB from './packet/ObjectB';
import SimpleObject from './packet/SimpleObject';
import IByteBuffer from "./IByteBuffer";
const protocols = new Map<number, any>();
@@ -26,14 +27,14 @@ class ProtocolManager {
return protocol;
}
static write(buffer: any, packet: any): void {
static write(buffer: IByteBuffer, packet: any): void {
const protocolId = packet.protocolId();
buffer.writeShort(protocolId);
const protocol = ProtocolManager.getProtocol(protocolId);
protocol.write(buffer, packet);
}
static read(buffer: any): any {
static read(buffer: IByteBuffer): any {
const protocolId = buffer.readShort();
const protocol = ProtocolManager.getProtocol(protocolId);
const packet = protocol.read(buffer);