completed _r_serialize with handles the first malloc of the buffer