UUID Buffer Module

Hey all. I made a simple module (under 50 LOC) to generate new UUIDs into a buffer, which is more memory efficient than a string containing the UUID from HttpService:GenerateGUID(). You can also convert a UUID buffer into a string, as well as create a UUID buffer from a string.

The buffers created by this module contain the UUIDs themselves and not the string representation of them.

I was inspired by a thread asking for making UUIDs smaller so they don’t use as much bandwidth when sent over the network. Someone suggested to use numbers or buffers, and I thought why not?

This version is very simple and doesn’t contain any checks on inputs other than basic Luau typings, use with care.

It contains 3 functions:

  • Generate(): buffer
    • Returns a 128-bit buffer containing a random UUID
  • tostring(UUIDBuffer: buffer, wrapInCurlyBraces: boolean?): string
    • Returns a string generated from the provided buffer. Wraps the output in curly braces unless the optional wrapInCurlyBraces argument is false, similar to GenerateGUID.
  • fromstring(UUIDString: string): buffer
    • Returns a 128-bit buffer containing a UUID parsed from the provided string. Any characters other than hexadecimal digits are ignored.

Example:

local UUIDBuffer = require(game:GetService("ReplicatedStorage"):FindFirstChild("UUIDBuffer"))
local UUID: buffer = UUIDBuffer.Generate()

print(UUID)
--->  buffer: 0x57f8f16ebee85d65

print(UUIDBuffer.tostring(UUID))
--->  {c499365f-8ddd-fd9c-20cd-69cad7ef2896}

print(UUIDBuffer.tostring(UUID, false))
--->  c499365f-8ddd-fd9c-20cd-69cad7ef2896

local secondUUID = UUIDBuffer.fromstring("1c439509-2e0b-03a3-a4ab-f3908eed945e")

print(secondUUID)
--->  buffer: 0xc8ab2028a219edfd

print(UUIDBuffer.tostring(secondUUID))
--->  {1c439509-2e0b-03a3-a4ab-f3908eed945e}
2 Likes