Hi Zach,
In order to convert a byte array to a word array without copying, you must first ensure that the bytes are aligned -- that is, they start on an 8-byte boundary (or 4-byte for 32-bit systems). If you try to use non-aligned data, you may see crashes or slowness (depending on CPU architecture).
Sometimes you can be sure that your data is aligned by virtue of the context -- for example, arrays allocated by malloc() are aligned. But if you don't know for sure, it's safest to make a copy. You can also check at runtime by converting the pointer into an integer and doing arithmetic.
*If* the bytes are aligned, then you can use reinterpret_cast to convert, like:
kj::ArrayPtr<capnp::word> words(reinterpret_cast<const byte*>(bytes.begin()), bytes.size() / sizeof(capnp::word));
Alternatively, to make a copy, do:
auto words = kj::heapArray<capnp::word>(bytes.size() / sizeof(capnp::word));
memcpy(words.begin(), bytes.begin(), words.asBytes().size());
-Kenton