Refactor the serialize code.
Optimized ByteBufferStream allocate & free
Refactor the unserialize code.