protocol: fix encode bug that cause coredump