bson c driver

378 views
Skip to first unread message

Claudio Bisegni

unread,
Apr 22, 2012, 4:47:06 PM4/22/12
to bs...@googlegroups.com
Hi,
i'm trying to use bson c driver instead cpp due to a bug in ccp version when running on arm. 

i'm trying to deserialize a bson so i used this:

bson = bson_create();

bson_init_data( bson , (char*)serializedBson);


this work but serializedBson is managed elsewhere so how can let bson will copy the data? there is an api?


last quesiton, someone has used the cpp version on arm? i need bson working on arm for a project but on this platform i have serious problem.


My arm is :

Linux ts7800 2.6.34 #17 PREEMPT Fri Nov 11 15:06:02 MST 2011 armv5tel GNU/Linux+


this is my gcc:

Using built-in specs.

Target: arm-linux-gnueabi

Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-sjlj-exceptions --enable-checking=release --build=arm-linux-gnueabi --host=arm-linux-gnueabi --target=arm-linux-gnueabi

Thread model: posix

gcc version 4.4.5 (Debian 4.4.5-8) 


thanks in advanced

Kyle Banker

unread,
Apr 23, 2012, 2:43:30 PM4/23/12
to bs...@googlegroups.com
Hi Claudio,

To answer your first question, there's currently no API for transferring ownership of a buffer. Feel free to suggest one if needed.

Typically when deserializing, you'll use a bson_iterator, not a raw bson object. In that case, you'd use bson_iterator_from_buffer().

Kyle

Bisegni Claudio

unread,
Apr 23, 2012, 3:19:38 PM4/23/12
to bs...@googlegroups.com
Hi Kyle,
thank for replay. I'll try your hint. I have another question: there is a way to reopen a bson struct that is finalized? it will be useful in many situation.

thanks

Kyle Banker

unread,
Apr 30, 2012, 10:45:39 AM4/30/12
to bs...@googlegroups.com
No. Once finalized, BSON structs are immutable.

hergertme

unread,
Nov 3, 2012, 5:45:03 AM11/3/12
to bs...@googlegroups.com
If you use my[1] BSON implementation for C, you can do all of which you requested here.

For creating new structures, you have:
  • mongo_bson_new_from_data to create a new structure copying the data.
  • mongo_bson_new_take_data to create and take ownership of data (must be freeable with g_free, but generally that works for anyting with free).
And for building, every append also updates the message length header so it is always in valid state. (But I would suggest not modifying it after passing it around). It is reference counted as well (mongo_bson_ref, mongo_bson_unref).

[1] https://github.com/chergert/mongo-glib/blob/master/mongo-glib/mongo-bson.c
Reply all
Reply to author
Forward
0 new messages