
A diagnostic endpoint carries a small binary attachment inside JSON. The file appears to grow between capture and upload because the transport needs a text representation. Three source bytes map to four Base64 characters. Short final groups use padding, which makes a one-byte file look disproportionately expensive.
A small Python implementation
The script runs base64.b64encode against three independent inputs. Each call starts from the value shown, so changing one example leaves the other expectations available for comparison. The table records real return values from the example. Quotation marks around text in the table make its boundaries visible.
import base64
def evaluate(value):
return base64.b64encode(bytes.fromhex(value)).decode('ascii')
for sample in ['ff', 'ffff', 'ffffff']:
print(evaluate(sample))What the three inputs produce
| Input to evaluate | Observed result |
|---|---|
| 'ff' | '/w==' |
| 'ffff' | '//8=' |
| 'ffffff' | '////' |
For 'ff', the observed output is '/w=='. With 'ffff', it becomes '//8='. Compare the two as a before-and-after record. Keeping the input beside the expectation makes it possible to distinguish an intentional contract change from a change introduced by a different parser or runtime.
The result for 'ffffff' is text, '////'. Compare the resulting characters directly in a test. If two outputs look identical on screen, printing a quoted representation can expose a trailing space, a line boundary or an escaped character.
Choosing the behaviour to ship
The JSON wrapper and transport headers add separate overhead. A large attachment may fit better as a binary object with a reference.
A practical test can begin with assert evaluate('ff') == '/w=='. Add the other rows as separate expectations so one failure identifies the input that changed. For a service fed by stored data, repeat the check on one anonymized record from an earlier version of its file or message format.
The boundary case most likely to be missed
Compare a binary upload and a JSON-wrapped transfer with the same source bytes and transport conditions. A larger encoded body might still be convenient for a very small diagnostic message, while a bulk upload can justify a separate binary endpoint.
The same Python function was also run with '' / 'ff ' / 'ff'. These additional inputs change the boundary without changing the implementation. An exception name in the table records where the operation rejects an input; a returned empty or zero value records a successful call. Choose deliberately which of those outcomes the surrounding feature should expose.
| Additional fixture | Result or exception |
|---|---|
| '' | '' |
| 'ff ' | '/w==' |
| 'ff' | '/w==' |
Python’s base64 reference · Python standard library
Sources and further reading
Cover photograph: Usbkey internals edit by John Fader. CC BY-SA 3.0. Cropped and typeset for this cover. The photograph illustrates the topic. This image adaptation uses the same share-alike license.
