Skip to content

Instantly share code, notes, and snippets.

@jerrylususu
Created April 27, 2023 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerrylususu/fd9013b2be6543b188c745fcf431ae3b to your computer and use it in GitHub Desktop.
Save jerrylususu/fd9013b2be6543b188c745fcf431ae3b to your computer and use it in GitHub Desktop.
protobuf string to base64
<!DOCTYPE html>
<html>
<head>
<title>Base64 Encoder</title>
</head>
<body>
<textarea id="myTextArea" rows="10" cols="50"></textarea>
<br>
<button onclick="encodeText()">Encode to Base64</button>
<br>
<pre id="encodedText"></pre>
<script>
function encodeText() {
let text = document.getElementById("myTextArea").value;
console.log("text", text);
let rawValue = eval('"' + text + '"');
const result = [];
for (let i = 0; i < rawValue.length; i++) {
result.push(rawValue.charCodeAt(i));
}
const uint8array = new Uint8Array(result);
let base64Encoded = btoa(String.fromCharCode.apply(null, uint8array));
document.getElementById("encodedText").innerText = base64Encoded;
}
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment