Add encode and decode function changes

add encode and decode functions
add flush command and handled timeout issue
Merge pull request #1 from sagarnaik/master

Add encode and decode function changes