Add Base Conversion Functions
complete
Signal Linden
It would be terrific to have a function or family of functions to convert between popular binary-as-text representations. This could be used, for example, to take the base64 output of
llHMAC
and convert it to the more commonly used base16 (hex) encoding.Option 1:
llBase64ToBase16(string src)
llBase16ToBase64(string src)
Option 2 (Suggestion from Bleuhazenfurfle):
string llBaseToBase(string src, string from, string into)
Rationale
Working with base64 and base16 encoded data is relatively common, (JWTs, digests, et al.) and converting between one and the other is also a frequent demand. This is currently rather arduous and expensive with LSL. As an example of a practical application: the
llHMAC
function returns base64 but most applications using HMAC expect hex.Log In
V
VriSeriphim Resident
First, thanks.
Second, just occurred to me that LlBaseToInteger and LlIntegerToBase would also (a) be useful and (b) more efficient in terms of server CPU usage.
This post was marked as
complete
Signal Linden
in progress
Vincent Nacon
Second option would be better, so we can expand with more new encodings in the future.
Woolfyy Resident
Vincent Nacon +1 knowing that it is the way my own number conversion function works :-) so i will get a smaller code for it ... well ... for part of it :-)
A much complete stuff would be to also add DEG RAD etc conversion in spite of just limiting it to base conversion ... i-e in a more powerful function :
string llConvert(string src, string from, string into) you would also have the ability to do llConvert("90", DEG, RAD) to convert from degrees to radians
... knowing that if it is flags used it could for example do combined conversions on vectors, rotations, encoding, base etc.
Example :
llConvert("< 128.0, 127.252525, 1326.56T75675>", VECTOR, INTEGER+ROUND) to get an integer split in 3 parts including 128 / 127 / 1326
or
llConvert( (string)NULL_VECTOR, VECTOR, COLOR_NAME) to get BLACK
or
llConvert( (string)NULL_VECTOR, VECTOR, COLOR_NAME) to get its HTML code
etc.
just to say that llBaseToBase() is quite simplistic compared to the full range of needs that could be satisfied creating a real conversion library, keeping in mind that Signal Linden Option 1 is great too as it is compact and efficient for its specific use, meaning that it is not one option against another option but maybe 2 flavors, the second one needing maybe more options in the conversion library style.
Signal Linden
tracked
Signal Linden
under review