Created
March 29, 2025 18:56
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "linden_common.h" | |
#include "lscript_library.h" | |
#include "llbase64.h" | |
#include <cstring> // For memcpy | |
#include <netinet/in.h> // For htonl | |
void llFloatToBase64(LLScriptLibData *retval, LLScriptLibData *args, const LLUUID &id) | |
{ | |
retval->mType = LST_STRING; | |
F32 floatval = args[0].mFP; | |
uint32_t value; | |
memcpy(&value, &floatval, sizeof(floatval)); | |
value = htonl(value); | |
std::string binary(4, '\0'); | |
binary[0] = (value >> 24) & 0xFF; | |
binary[1] = (value >> 16) & 0xFF; | |
binary[2] = (value >> 8) & 0xFF; | |
binary[3] = value & 0xFF; | |
std::string encoded = LLBase64::encode(binary); | |
retval->mString = strdup(encoded.c_str()); | |
} | |
void llBase64ToFloat(LLScriptLibData *retval, LLScriptLibData *args, const LLUUID &id) | |
{ | |
retval->mType = LST_FLOATINGPOINT; | |
std::string decoded = LLBase64::decode(args[0].mString); | |
if (decoded.size() < 4) | |
{ | |
retval->mFP = 0; | |
return; | |
} | |
int value = (static_cast<unsigned char>(decoded[0]) << 24) | | |
(static_cast<unsigned char>(decoded[1]) << 16) | | |
(static_cast<unsigned char>(decoded[2]) << 8) | | |
(static_cast<unsigned char>(decoded[3])); | |
value = htonl(value); | |
memcpy(&(retval->mFP), &value, sizeof(retval->mFP)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment