[CDRIVER-2064] Add bson_iter_init_from_data function Created: 22/Feb/17  Updated: 24/Jan/18  Resolved: 28/Feb/17

Status: Closed
Project: C Driver
Component/s: libbson
Affects Version/s: None
Fix Version/s: 1.7.0

Type: New Feature Priority: Major - P3
Reporter: David Golden Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CXX-984 Improve use of bson_init_static Closed
Related
related to CDRIVER-2467 Provide a way to synthesize a bson_it... Closed

 Description   

The mongocxx driver would benefit from the ability to directly initialize a bson_iter_t from a data buffer, rather than having to repetitively call bson_init_static merely to call bson_iter_init. As bson_iter_init only uses the passed bson_t to extract a buffer pointer and length, we'd like an alternative initializer for bson_iter_t that takes those directly.

A PR will follow shortly.



 Comments   
Comment by A. Jesse Jiryu Davis [ 28/Feb/17 ]

There were good reasons not to do this. First, that future users will wonder why we don't now have bson_iter_init_find_from_data, etc. Second, that it violates the object hierarchy that organizes libbson: raw data creates bson_t creates bson_iter_t. But practicality beats purity, and the reasons for adding this function won.

Comment by A. Jesse Jiryu Davis [ 28/Feb/17 ]

https://github.com/mongodb/libbson/commit/02dc4612a28041a5ca808789f2501e147ea35e6c

https://github.com/mongodb/libbson/commit/b643cc3b38fcf3158a732aaf7b152ba089efa423

Comment by Hannes Magnusson [ 22/Feb/17 ]

Thanks for the context and adding the relation to CXX-984. I could not have known from the description.

Comment by David Golden [ 22/Feb/17 ]

We need this for internal optimization. We can't initialize a bson_t with bson_init_static and cache it because of the problem mentioned in CDRIVER-2065. If you'd like to fix that problem (by providing a copyable static bson_t implementation), that would work, too, but this is a more direct fix, as bson_iter_t is just a wrapper around a buffer pointer anyway. Sam and I have already discussed this issue with Jesse as part of our work on CXX-984 and this was Jesse's recommended approach.

I don't want to add bson_iter_init_from_data_find because I don't think those functions should ever have been combined in the first place. You're welcome to add that if you think it's important.

Comment by Hannes Magnusson [ 22/Feb/17 ]

I'm skeptical about this. It seems like a helper function the app itself should be providing.
Going down this road, why not add

bson_iter_init_from_data_find (data, "key")

Comment by David Golden [ 22/Feb/17 ]

PR: https://github.com/mongodb/libbson/pull/182

Generated at Wed Feb 07 21:14:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.