rewrite bytes2frames to C++