5075

Bytes vs Text

Algorithm
Medium
Pro
streams
encoding
blob
base64

Bytes vs Text

Your extension exchanges files with a Nordic logistics partner: you hand their portal a blob, they hand one back. Their spec is blunt — "UTF-8 or UTF-16, tell us which, and don't choke on a byte order mark". Half the encoding bugs in real Business Central projects trace back to a stream that was opened without saying which encoding it speaks, and the corrupted æøå is found in production weeks later. You are writing the one codec both directions go through, and it is graded on the exact bytes.

Requirements

Create a codeunit named "Text Blob Codec" with two public procedures:

procedure ExportText(Content: Text; Encoding: TextEncoding; var TempBlob: Codeunit "Temp Blob")
procedure ImportText(TempBlob: Codeunit "Temp Blob"; Encoding: TextEncoding): Text

Rules — this is the whole contract, and every rule is graded:

  1. ExportText replaces the blob's content entirely: afterwards the blob holds exactly the bytes of Content encoded with Encoding — no byte order mark of your own, no terminator, and no stale bytes left over from whatever the blob held before. Callers reuse one blob across exports.
  2. Exporting empty text produces a zero-length blob.
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

Solve it with Pro

You’re reading the opening of the statement. Pro unlocks the whole problem:

  • The full statement
  • Starter code in the browser editor
  • 14 grading tests, run on Business Central 28.5
  • 3 hints
  • The reference solution

Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade