Implement codec and add unit tests