use buffer to speed up encode/decode