Name

with_binary_output — evaluate a script while the response channel is configured for binary output.

Synopsis

::rivet::with_binary_output script

Description

Flushes stdout, saves its channel configuration, configures it with -translation binary, and evaluates script. After flushing the binary output, the previous translation, encoding, and end-of-file character settings are restored. Restoration also takes place when the script returns an error or another non-standard Tcl completion code.

Use this command to group multiple binary writes. Values written in the script must be byte-oriented Tcl values whose characters are in the range U+0000 through U+00FF. Text that is to form part of a binary protocol must first be converted explicitly, for example with encoding convertto utf-8.

::rivet::with_binary_output {
    puts -nonewline stdout $headerBytes
    puts -nonewline stdout $payloadBytes
}
[Note]Note
This command is not placed in the export list of the ::rivet namespace