add buildByteArray method and tests for it