superficially complete implementation of encode