More efficient encoding using TypedArrays.