Switch pb_encode to use the common iterator logic in pb_common.c