This is a proposal for a WG2 bytevector API. The conceit is that everything is a separate procedure with minimal arguments; this makes for a *lot* of procedures, but each one can be easily inlined by even a very dumb compiler, providing high efficiency.

(bytevector-<type><endian>-ref *bytevector n*)

Returns a Scheme number corresponding to the binary value encoded according to *type* beginning at offset *n* in *bytevector*.

(<type><endian>vector-ref *bytevector n*)

Returns a Scheme number corresponding to the binary value encoded according to *type* beginning at offset *n* in *bytevector*, where *n* is first multiplied by a value corresponding to the size of the binary value.

(bytevector-<type><endian>-set! *bytevector n v*)

Converts *v* to a binary value encoded according to *type* and places it into *bytevector* beginning at offset *n*.

(<type><endian>vector-set! *bytevector n v*)

Converts *v* to a binary value encoded according to *type* and places it into *bytevector* beginning at offset *n*, where *n* is first multiplied by a value corresponding to the size of the binary value.

(<type><endian>vector-length *bytevector*)

Returns a Scheme number corresponding to length of *bytevector*divided by a value corresponding to the size of the binary value.

The types are:

- u8
- unsigned 8-bit integer
- s8
- signed 8-bit integer
- u16
- unsigned 16-bit integer
- s16
- signed 16-bit integer
- u32
- unsigned 32-bit integer
- s32
- signed 32-bit integer
- u64
- unsigned 64-bit integer
- s64
- signed 64-bit integer
- u128
- unsigned 128-bit integer
- s128
- signed 128-bit integer
- f32
- 32-bit float
- f64
- 64-bit float
- c64
- 64-bit complex number (two 32-bit floats, real followed by imaginary)
- c128
- 128-bit complex number (two 64-bit floats, real followed by imaginary)

The endianism values are:

- (empty)
- Native representations (system-dependent)
- le
- Little-endian (for float and complex, IEEE format)
- be
- Big-endian (for float and complex, IEEE format)

Endianism is not applicable to the u8 and s8 types.

- (bytevector-<encoding>-ref
*bytevector n l*) - Returns a Scheme string corresponding to the binary value encoded according to
*encoding*beginning at offset*n*in*bytevector*and continuing for*l*bytes. - (bytevector-<encoding>-set!
*blob n v*) - Converts
*v*to a binary string encoded according to*encoding*and places it into*bytevector*beginning at offset*n*. Returns the number of bytes encoded.

- utf8
- UTF-8 encoding
- utf16
- UTF-16 encoding (respects BOM if present, defaults to native encoding otherwise)
- utf16be
- UTF-16BE encoding (treats BOM as a normal character)
- utf16le
- UTF-16LE encoding (treats BOM as a normal character)

**TBD**