Add generalized encoding capabilities, with testing.