binarymodule binary
// Basics
def empty : binary // since PR 1657
def length : binary -> number
def sub : number -> number -> binary -> binary
// sub(startByte, endByte, b)
def concat : binary -> array(binary) -> binary
// concat(separator, byteArrays)
def concatStream : binary -> stream(binary) -> binary // since PR1817
def indexOfLeft : binary -> binary -> number
// indexOfLeft(toSearch, buffer)
def byteAt : number -> binary -> number // since PR1817
def fromByte : number -> binary // since PR1817
// Conversions
def ofString : string -> binary
def toString : binary -> string
def toStringResult : binary -> result(string,string) // since PR1545
def ofBase64 : string -> binary
def ofBase64Result : string -> result(string,binary) // since PR1545
def toBase64 : binary -> string
def ofHex : string -> binary // since PR1817
def ofHexResult : string -> result(string,binary) // since PR1817
def toHex : binary -> string // since PR1817
def ofToken : token -> binary
def formatRmxCode : data -> result(string,binary) // since PR1581
def parseRmxCode : binary -> result(string,data) // since PR1581
module end
def empty : binary // since PR 1657
def length : binary -> number
def sub : number -> number -> binary -> binary
// sub(startByte, endByte, b)
def concat : binary -> array(binary) -> binary
// concat(separator, byteArrays)
def concatStream : binary -> stream(binary) -> binary // since PR1817
// concatStream(separator, byteArrays)
def indexOfLeft : binary -> binary -> number
// indexOfLeft(toSearch, buffer)
def byteAt : number -> binary -> number // since PR1817
def fromByte : number -> binary // since PR1817
A binary is a sequence of bytes:
empty is the empty sequencelength(b) returns the number of bytessub(startByte,endByte,b) returns the sub-sequence starting at subByte until the byte before endByte as a new binary (no sharing with the input)concat(sep,bb) concatenates the binaries in the array bb and puts the binary sep between each of the inputsconcatStream(sep,bb) concatenates the binaries in the stream bb and puts the binary sep between each of the inputs. This function is optimized for long, open-ended streams.indexOfLeft(toSearch, b) searches for the sequence toSearch inside b and returns the start position of the leftmost occurrence (or undefined if not occurring)byteAt(pos, b) returns the value of the byte at pos (range 0 to 255)fromByte(byte) creates a binary sequence of just one byte and puts the given byte into it def ofString : string -> binary
def toString : binary -> string
def toStringResult : binary -> result(string,string) // since PR1545
def ofBase64 : string -> binary
def ofBase64Result : string -> result(string,binary) // since PR1545
def toBase64 : binary -> string
def ofHex : string -> binary // since PR1817
def ofHexResult : string -> result(string,binary) // since PR1817
def toHex : binary -> string // since PR1817
def ofToken : token -> binary
def formatRmxCode : data -> result(string,binary) // since PR1581
def parseRmxCode : binary -> result(string,data) // since PR1581
Note that strings are sequences of characters. toString(b) checks that b conforms to the UTF-8 representation of characters, and returns the corresponding string (as copy). If the check fails, a runtime error is thrown. The variant toStringResult returns ok(s) if all is good, or error(msg) if a problem arises.
ofString is failsafe, and returns the UTF-8 representation of the string (as copy).
toBase64 returns a single line (no linefeeds at all) with the standard Base64 encoding (using the special characters + and /), and with padding (using = characters).
ofBase64 is somewhat more liberal, and also accepts - instead of +, and _ instead of /, and the padding is allowed to be missing.
toHex returns a string where each byte is represented by a 2-digit hex code (lowercase a-f).
ofHex parses such a string back. Here, uppercase A-F are also accepted.
ofTokenThe binary representation of a token (NB This can fail if the runtime prevents the conversion to binaries).
formatRmxCode returns the input represented in the internal encoding of the runtime.