Implement codec classes

Nit: there's some extra indentation here.