Facepunch / garrysmod-requests

Feature requests for Garry's Mod
86 stars 24 forks source link

SteamID64 stream reader & writer convenience methods #2148

Closed WilliamVenner closed 1 year ago

WilliamVenner commented 1 year ago

Details

The most common use case of writing larger-than-32-bit integers to the net stream or a file is probably for SteamID64s.

Currently, it's wasteful to write a SteamID64 to one of these streams as it must be written as a string. That means your average SteamID64 is going to take up 136 bits (17 bytes).

Whilst 17 bytes is nothing to panic about, it would be trivial to implement the following methods:

These methods would cover 99% of use cases for writing larger-than-32-bit integers to the respective streams in Garry's Mod and would help keep the size of SteamID64-heavy net messages and files down.

Additionally, it would make some net message code easier to write. String SteamID64s are actually technically not always 17 bytes, so keeping track of the remaining length of the buffer would be made easier, for example. (It should be acknowledged however that net.BytesLeft() does exist)

* For anyone reading that needs to more efficiently send SteamID64s you can use a big hack I wrote here in the mean time

robotboy655 commented 1 year ago

Added net.Write/ReadUInt64 and File:Write/ReadUInt64

They accept and return string values, and can be used with Player:SteamID64()