Standard library - binary

module 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

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
    // 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:

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

to/of string

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).

to/of base64

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.

to/of hex

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.

ofToken

The binary representation of a token (NB This can fail if the runtime prevents the conversion to binaries).

RmxCodec

formatRmxCode returns the input represented in the internal encoding of the runtime.