Convert encoder.c to C++