I am working on a standalone BSON C++ API. At present I have a couple of issues with my BSON serialiser, so am using the C API to generate the bson. I do not see any functions to set the size (the first 4 bytes of the document as per spec) of the BSON data, neither could I find anything appropriate in the test suite for the C driver. bsondump generates the following error trace when I use it to read my test bson output
It may be that my logic is false when generating the BSON. The basic workflow is as follows:
::bson b;
bson_init_size( &b, document.getSize() );
// iterator over elements in document and based on element type invoke appropriate bson_append_xxx functions
bson_finish( &b );
bson_destroy( &b );
bsondump /tmp/doctest.bson
{ "_id" : ObjectId( "506b931b44c193650000feff" ), "double" : 1, "string" : "string value", undefined, "boolean" : true, "date" : Date( 1349209034000 ), "null" : null, "regex" : /^abc/, "integer" : 1, "long" : 2 }
Wed Oct 3 09:39:22 Assertion: 10334:Invalid BSONObj size: 0 (0x00000000) first element: EOO
0x107aa3dd9 0x107aaa67e 0x107a5a93f 0x107d7ba30 0x107d7d85c 0x107d7b475 0x107d79063 0x107d7ce21 0x7fff8c2667e1
0 bsondump 0x0000000107aa3dd9 _ZN5mongo15printStackTraceERSo + 57
1 bsondump 0x0000000107aaa67e _ZN5mongo11msgassertedEiPKc + 350
2 bsondump 0x0000000107a5a93f _ZNK5mongo7BSONObj14_assertInvalidEv + 847
3 bsondump 0x0000000107d7ba30 _ZN5mongo8BSONTool11processFileERKN5boost11filesystem210basic_pathISsNS2_11path_traitsEEE + 1184
4 bsondump 0x0000000107d7d85c _ZN8BSONDump5doRunEv + 1212
5 bsondump 0x0000000107d7b475 _ZN5mongo8BSONTool3runEv + 997
6 bsondump 0x0000000107d79063 _ZN5mongo4Tool4mainEiPPc + 9427
7 bsondump 0x0000000107d7ce21 main + 49
8 libdyld.dylib 0x00007fff8c2667e1 start + 0
assertion: 10334 Invalid BSONObj size: 0 (0x00000000) first element: EOO