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>-ref bytevector n)
Returns a Scheme number corresponding to the binary value encoded according to type beginning at offset n in bytevector. This procedure treats bytevector as potentially containing more than one type.
(<type>vector-ref bytevector n)
Returns a Scheme number corresponding to the binary value encoded according to type beginning at offset n * b in bytevector, where b is the size of the binary value in bytes. This procedure treats bytevector as a uniformly typed vector.
(bytevector-<type>-set! bytevector n v)
Converts v to a binary value encoded according to type and places it into bytevector beginning at offset n. This procedure treats bytevector as potentially containing more than one type.
(<type>vector-set! bytevector n v)
Converts v to a binary value encoded according to type and places it into bytevector beginning at offset n * b, where b is the size of the binary value in bytes. This procedure treats bytevector as a uniformly typed vector.
(<type>vector-length bytevector)
Returns a Scheme number corresponding to the length of bytevectordivided by the size of the binary value in bytes.
(vector-><type>vector vector)
Returns a vector with the same elements as <type>vector.
(<type>vector->vector <type>vector)
Returns a <type>vector with the same elements as vector. It is an error if an element cannot be accurately converted to <type>.
A <type> consists of a <principal type> followed by an <endianism>.
The <principal type> values are:
The <endianism> values are:
Endianism is not applicable to the u8 and s8 types.
TBD