Template for encoder/decoder to support multiple index types