apps: fix encoding/decoding and chunk splitting