Refactor repetition & definition level encoding

They both do very similar things, so now there is one function that
is called by outer functions for both repetition & definition levels
encoding.  The outer functions do the appropriate logging and checks for
whether encoding their particular levels is necessary.