bson: more code reorg

Also, arrays and slices can be encoded as top
level documents without embedding.