reorganize C functions by encoding/decoding for clarity
reorganize C functions by encoding/decoding for clarity

This clusters encoding and decoding functions with "higher-level"
functions roughly at the top of each group.

The "array ref doc" special case was also refactored into its own
function, avdoc_to_bson, equivalent to hv_to_bson and ixhash_to_bson.

jorol/mongo-perl-driver,xdg/mongo-perl-driver,mongodb/mongo-perl-driver,mongodb/mongo-perl-driver,jorol/mongo-perl-driver,kainwinterheart/mongo-perl-driver,dagolden/mongo-perl-driver,xdg/mongo-perl-driver,gormanb/mongo-perl-driver,gormanb/mongo-perl-driver,dagolden/mongo-perl-driver,gormanb/mongo-perl-driver,dagolden/mongo-perl-driver,jorol/mongo-perl-driver,jorol/mongo-perl-driver,rahuldhodapkar/mongo-perl-driver,rahuldhodapkar/mongo-perl-driver,dagolden/mongo-perl-driver,kainwinterheart/mongo-perl-driver,kainwinterheart/mongo-perl-driver,rahuldhodapkar/mongo-perl-driver,xdg/mongo-perl-driver,kainwinterheart/mongo-perl-driver,gormanb/mongo-perl-driver,rahuldhodapkar/mongo-perl-driver,mongodb/mongo-perl-driver