decode example is merged to encode, with better API