#include<bson.h>typedefstruct{/* run before / after descending into a document */bool(*visit_before)(constbson_iter_t*iter,constchar*key,void*data);bool(*visit_after)(constbson_iter_t*iter,constchar*key,void*data);/* corrupt BSON, or unsupported type and visit_unsupported_type not set */void(*visit_corrupt)(constbson_iter_t*iter,void*data);/* normal bson field callbacks */bool(*visit_double)(constbson_iter_t*iter,constchar*key,doublev_double,void*data);bool(*visit_utf8)(constbson_iter_t*iter,constchar*key,size_tv_utf8_len,constchar*v_utf8,void*data);bool(*visit_document)(constbson_iter_t*iter,constchar*key,constbson_t*v_document,void*data);bool(*visit_array)(constbson_iter_t*iter,constchar*key,constbson_t*v_array,void*data);bool(*visit_binary)(constbson_iter_t*iter,constchar*key,bson_subtype_tv_subtype,size_tv_binary_len,constuint8_t*v_binary,void*data);/* normal field with deprecated "Undefined" BSON type */bool(*visit_undefined)(constbson_iter_t*iter,constchar*key,void*data);bool(*visit_oid)(constbson_iter_t*iter,constchar*key,constbson_oid_t*v_oid,void*data);bool(*visit_bool)(constbson_iter_t*iter,constchar*key,boolv_bool,void*data);bool(*visit_date_time)(constbson_iter_t*iter,constchar*key,int64_tmsec_since_epoch,void*data);bool(*visit_null)(constbson_iter_t*iter,constchar*key,void*data);bool(*visit_regex)(constbson_iter_t*iter,constchar*key,constchar*v_regex,constchar*v_options,void*data);bool(*visit_dbpointer)(constbson_iter_t*iter,constchar*key,size_tv_collection_len,constchar*v_collection,constbson_oid_t*v_oid,void*data);bool(*visit_code)(constbson_iter_t*iter,constchar*key,size_tv_code_len,constchar*v_code,void*data);bool(*visit_symbol)(constbson_iter_t*iter,constchar*key,size_tv_symbol_len,constchar*v_symbol,void*data);bool(*visit_codewscope)(constbson_iter_t*iter,constchar*key,size_tv_code_len,constchar*v_code,constbson_t*v_scope,void*data);bool(*visit_int32)(constbson_iter_t*iter,constchar*key,int32_tv_int32,void*data);bool(*visit_timestamp)(constbson_iter_t*iter,constchar*key,uint32_tv_timestamp,uint32_tv_increment,void*data);bool(*visit_int64)(constbson_iter_t*iter,constchar*key,int64_tv_int64,void*data);bool(*visit_maxkey)(constbson_iter_t*iter,constchar*key,void*data);bool(*visit_minkey)(constbson_iter_t*iter,constchar*key,void*data);/* if set, called instead of visit_corrupt when an apparently valid BSON * includes an unrecognized field type (reading future version of BSON) */void(*visit_unsupported_type)(constbson_iter_t*iter,constchar*key,uint32_ttype_code,void*data);bool(*visit_decimal128)(constbson_iter_t*iter,constchar*key,constbson_decimal128_t*v_decimal128,void*data);void*padding[7];}bson_visitor_tbson_visitor_t;

The bson_visitor_t structure provides a series of callbacks that can be called while iterating a BSON document. This may simplify the conversion of a bson_t to a higher level language structure.

If the optional callback visit_unsupported_type is set, it is called instead of visit_corrupt in the specific case of an unrecognized field type. (Parsing is aborted in either case.) Use this callback to report an error like “unrecognized type” instead of simply “corrupt BSON”. This future-proofs code that may use an older version of libbson to parse future BSON formats.