Fix marshaling the size prefix and add some tests