src: implement encode method

- Add serial property to setting object.
- Modify example to encode and decode.
example: handle errors