I'm not a huge fan of this loop. We should write the right primitive type while we are reading the data and not at the end (especially when it's not necessarily).

I though we had a talk pending on this topic (I don't find the thread anymore) Anyway, It will be better to get the right data when we are reading it and do the necessary operation at this time.