$Base64 Encode: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
(Automatically generated page update)
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:
<span class="pageSubtitle">Convert byte string to base64</span>
<span class="pageSubtitle">Convert byte string to base64</span>


<p class="warn"><b>Note: </b>Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $Base64_Encode function is the <var>[[StringToBase64 (String function)|StringToBase64]]</var> function.</p>
<p class="warn"><b>Note: </b>Many $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $Base64_Encode function is the <var>[[StringToBase64 (String function)|StringToBase64]]</var> function.</p>


This function converts a byte string into its base64 encoding. It is identical to <var>[[$Lstr_Base64_Encode]]</var> with the (hopefully obvious) exception that it is not [[Longstrings|longstring capable]]. As such, <var>$Lstr_Base64_Encode</var> is recommended over <var>$Base64_Encode</var> as it is a more flexible version of the latter.  
This function converts a byte string into its base64 encoding. It is identical to <var>[[$Lstr_Base64_Encode]]</var> with the (hopefully obvious) exception that it is not [[Longstrings|longstring capable]]. As such, <var>$Lstr_Base64_Encode</var> is recommended over <var>$Base64_Encode</var> as it is a more flexible version of the latter.  
Line 48: Line 48:
==Products authorizing {{PAGENAMEE}}==  
==Products authorizing {{PAGENAMEE}}==  
<ul class="smallAndTightList">
<ul class="smallAndTightList">
<li>[[Sirius functions]]</li>
<li>[[List of $functions|Sirius functions]]</li>
<li>[[Fast/Unload User Language Interface]]</li>
<li>[[Fast/Unload User Language Interface]]</li>
<li>[http://m204wiki.rocketsoftware.com/images/4/4a/JoclrNew.pdf Janus Open Client]</li>
<li>[[Media:JoclrNew.pdf|Janus Open Client]]</li>
<li>[http://m204wiki.rocketsoftware.com/images/1/17/JosrvrNew.pdf Janus Open Server]</li>
<li>[[Media:JosrvrNew.pdf|Janus Open Server]]</li>
<li>[[Janus Sockets]]</li>
<li>[[Janus Sockets]]</li>
<li>[[Janus Web Server]]</li>
<li>[[Janus Web Server]]</li>
<li>Japanese functions</li>
<li>Japanese functions</li>
<li>[http://m204wiki.rocketsoftware.com/images/4/4b/SirfieldNew.pdf Sir2000 Field Migration Facility]</li>
<li>[[Media:SirfieldNew.pdf|Sir2000 Field Migration Facility]]</li>
</ul>
</ul>




[[Category:$Functions|$Base64_Encode]]
[[Category:$Functions|$Base64_Encode]]

Latest revision as of 22:51, 20 September 2018

Convert byte string to base64

Note: Many $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $Base64_Encode function is the StringToBase64 function.

This function converts a byte string into its base64 encoding. It is identical to $Lstr_Base64_Encode with the (hopefully obvious) exception that it is not longstring capable. As such, $Lstr_Base64_Encode is recommended over $Base64_Encode as it is a more flexible version of the latter.

The $Base64_Encode function accepts one argument and returns a string result which is the base64 encoding of that argument.

Syntax

%coded = $Base64_Encode(string)

  • %coded is a string result set to the base64 encoding of string.
  • %string is a byte string of length 189 or less. If this argument is longer than 189 bytes, the request is canceled.

Usage notes

  • Because the maximum length of the argument is 189 bytes, if you have a longer stream to encode, you can do it in pieces, where any piece is a multiple of 3 bytes long (3 bytes are evenly packed into 4 bytes of a base64 encoding). For example, if you have a byte string which is the concatenation of items in a Sirius $list, and you want to print the base64 encoding of that string, possibly producing multiple lines of length 80, you can use the following approach:

    %S = FOR %I FROM 1 TO $ListCnt(%L) %T = $ListInf(%L, %I) REPEAT WHILE $LEN(%S) + $LEN(%T) > 60 %X = 60 - $LEN(%S) %U = %S WITH $SUBSTR(%T, 1, %X) PRINT $Base64_Encode(%U) %T = $SUBSTR(%T, %X + 1) %S = END REPEAT %S = %S WITH %T END FOR PRINT $Base64_Encode(%S)

  • As of Sirius Mods Version 6.8, you can do base64 encoding of strings longer than 255 bytes using $Lstr_Base64_Encode, but if, as in the example above, the intent is to break the result into smaller chunks, anyway, there probably wouldn't be a marked difference between using $Base64_Decode or its longstring equivalent.
  • $Base64_Decode is the inverse of $Base64_Encode.

Example

Given this argument of length 3:

%junk = $Base64_Encode($X2C('001083'))

%junk would be set to the byte string (of length 4) represented in character as ABCD.

Products authorizing $Base64_Encode