Move to mg_util.h so encode and decode are next ot each other. Pull out mg_next_list_entry_n() for advanced use cases. Add unit tests.