Add `encode` method