Optional field (i.e. definition levels) encoding with unit test

Fixes an assumption that optional fields also required repetition
levels.  Adds unit test for optional fields.