CDN Hashes

Some endpoints, like the  provided by , don't provide a full CDN URL and only provide raw hashes, like this:. We need to turn this into a full CDN URL. A CDN URL looks like  where   is the CDN number. The CDN number ranges from 0 to 7, so you might be tempted to send a request to, then  , and keep going until you reach the one containing the object. This works, but it's quite wasteful as you send up to 8 requests for just one object. There's a better way to do this. We can define a variable as 31, loop through the first 32 characters in the string, and in each iteration set the variable to itself bitwise XORed against the integer representation of that character (or, alternatively, the integer version of the hex value)

Examples
Python = JavaScript = C# = Ruby = C++ = C = Rust = Lua = Java = Kotlin = Crystal = FireX = using <"fx/internals/com.string.extensions">

com::string getCdnUrl(const com::string& hash) {   if (hash.isNullOrEmpty) throw new com::exception("Hash cannot be empty");

int i = 31;

// Could use an i32.pow here for faster math; hash.forEach(typeof(char), [=](char c) { i ^= c; });

// Could use an i32.mod here for faster math; return com::string::format("https://t%d.rbxcdn.com/%s", i % 8, hash); }