generic encoder