You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I just started using SmartBuffer to wrap client/server packets and so far it's working splendidly. 👌
That said, I just reached a point where I need to skip a few bytes when reading/writing a packet, because these bytes are "reserved" for something that isn't implemented yet. So I did the following to keep my read/write functions as concise as possible:
typePacketData={type: number;playerId: number;position: number;command: string;flags: number;timestamp: number;};functionreadPacket(packet: SmartBuffer): PacketData{return{type: packet.readUInt8(),playerId: packet.readUInt32LE(),position: packet.readUInt16LE(),command: packet.readStringNT(),flags: (packet.readOffset+=2)&&packet.readUInt8(),// skip and read.timestamp: packet.readUInt32LE(),};}functionwritePacket({ type, playerId, position, command, flags, timestamp }: PacketData): SmartBuffer{returnnewSmartBuffer().writeUInt8(type).writeUInt32LE(playerId).writeUInt16LE(position).writeStringNT(command).writeBuffer(Buffer.alloc(2))// skip by writing an empty buffer. can't set writeOffset since we don't have a reference to the buffer..writeUInt8(flags).writeUInt32LE(timestamp);}
As you can see from my efforts to keep things concise, the lines where I need to skip bytes are a little clunky.
I saw in v3 there was a skip method, but it was dropped in v4. What was the reason for dropping it and would you be open to the idea of adding it back in?
Also - just throwing this out there even though I don't think it would be as nice as a skip method - one idea I had as an alternative to skip was to add another param to the read/write methods. It would be a boolean that, if set to true, would make the offset you specified relative to the readOffset/writeOffset (and would also auto-increment them so you can chain further calls). Example:
Hi, I just started using SmartBuffer to wrap client/server packets and so far it's working splendidly. 👌
That said, I just reached a point where I need to skip a few bytes when reading/writing a packet, because these bytes are "reserved" for something that isn't implemented yet. So I did the following to keep my read/write functions as concise as possible:
As you can see from my efforts to keep things concise, the lines where I need to skip bytes are a little clunky.
I saw in v3 there was a
skip
method, but it was dropped in v4. What was the reason for dropping it and would you be open to the idea of adding it back in?Also - just throwing this out there even though I don't think it would be as nice as a
skip
method - one idea I had as an alternative toskip
was to add another param to the read/write methods. It would be a boolean that, if set totrue
, would make theoffset
you specified relative to thereadOffset
/writeOffset
(and would also auto-increment them so you can chain further calls). Example:wdyt? Thanks.
The text was updated successfully, but these errors were encountered: