Skip to content

Instantly share code, notes, and snippets.

Last active July 13, 2023 19:36
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Base64 optimization question on Twitter (
using System.Text.Json;
using System.Text.Json.Serialization;
var data = new[]
.Select(m => new Message(m)).ToArray();
var response = new Response(MessageBytesToString(data));
// Turn a list of messages into a single comma separated base64 encoded string
string MessageBytesToString(Message[] messages)
return string.Join(",", messages.Select(m => Convert.ToBase64String(m.Payload)));
class Message(byte[] bytes)
public byte[] Payload => bytes;
class Response(string messages)
public string Messages => messages;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment