Summary#
Three small encoding surfaces, spelled exactly as in C#, all pure (no capability, no using required):
var b64 = Convert.ToBase64String(bytes); // binary → base64 text
var back = Convert.FromBase64String(b64); // base64 → binary
var q = Uri.EscapeDataString("a b&c"); // "a%20b%26c" — safe in a URL
var safe = WebUtility.HtmlEncode("<b>hi</b>"); // "<b>hi</b>" — safe in HTML textSignature#
string Convert.ToBase64String(byte[] bytes) // Binary → base64 text
byte[] Convert.FromBase64String(string s) // base64 text → Binary
string Uri.EscapeDataString(string s) // percent-encode for a URL
string Uri.UnescapeDataString(string s) // reverse
string WebUtility.HtmlEncode(string s) // escape for HTML text
string WebUtility.HtmlDecode(string s) // reverseDescription#
Base64 — Convert.ToBase64String turns a Binary value (bytes, e.g. a file read via <span class="planned" title="this page is planned and not written yet">storage-file</span> or a
Binary property) into standard base64 text; Convert.FromBase64String reverses it. Use it to carry bytes inside a
JSON body or a text field.
URL escaping — Uri.EscapeDataString percent-encodes a string so it is safe inside a URL query value or path
segment (RFC 3986: a space becomes %20, & becomes %26, and so on). Uri.UnescapeDataString reverses it. Pair it
with Http.* when building a request URL from user input:
var url = "https://api.example.com/search?q=" + Uri.EscapeDataString(term);HTML escaping — WebUtility.HtmlEncode escapes &, <, >, " so a string is safe to place in HTML text
without injecting markup; WebUtility.HtmlDecode reverses it.
Not yet available. Raw UTF-8 byte conversion (Encoding.UTF8.GetBytes / GetString) is a planned follow-on —
Base64 already carries bytes as text, and JSON round-trips byte[] as base64 automatically. Ask for it when you need
raw UTF-8 bytes directly.
Examples#
Build a signed-looking token payload as base64:
string Encode(byte[] payload) {
return Convert.ToBase64String(payload);
}
byte[] Decode(string base64) {
return Convert.FromBase64String(base64);
}Escape user input into an outbound request (Http.*):
app Shop {
model "model/**/*.osy";
use Osyrin.Http; // `use` is a MANIFEST declaration — it belongs in app.osy
}
string Search(string term) {
var url = "https://api.example.com/search?q=" + Uri.EscapeDataString(term);
var r = Http.Get(url);
return r.Body;
}Render user text safely into an HTML fragment:
string Cell(string userText) {
return "<td>" + WebUtility.HtmlEncode(userText) + "</td>";
}