src: implement encode method

- Add serial property to setting object.
- Modify example to encode and decode.
example: handle errors
Merge pull request #1 from santigimeno/encode

Encode method implementation