Skip to content

Commit

Permalink
Add bs64 encode implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Virus-Axel committed Apr 8, 2023
1 parent b1c40fb commit 6a8fb08
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion addons/solana_client/scripts/bs64.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@ const mapping := [
]

static func encode(bytes: PackedByteArray) -> String:
return ""
var r: String = "";
var p: String = "";

var c = bytes.size() % 3;

if c > 0:
for i in range(c, 3):
p += '=';
bytes.append(0);

for i in range(0, bytes.size(), 3):
var n = (bytes[i] << 16) + (bytes[i + 1] << 8) + bytes[i + 2]

r += mapping[(n >> 18) & 63]
r += mapping[(n >> 12) & 63]
r += mapping[(n >> 6) & 63]
r += mapping[n & 63];

return r.substr(0, r.length() - p.length()) + p;


static func decode(str: String) -> PackedByteArray:
var ret := PackedByteArray()
Expand Down

0 comments on commit 6a8fb08

Please sign in to comment.