[CDRIVER-2494] Add a function to retrieve the key length on a bson_iter_t Created: 05/Feb/18  Updated: 07/Oct/21  Resolved: 31/Aug/18

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

Type: Improvement Priority: Minor - P4
Reporter: Kevin Albertson Assignee: Kevin Albertson
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

bson_iter_t knows the key length of the current element.

It computes the key length in _bson_iter_next_internal

   /* iterate from start to end of NULL-terminated key string */
   for (o = iter->off + 1; o < len; o++) {
      if (!data[o]) {
         iter->d1 = ++o;
         goto fill_data_fields;
      }
   }

And it does not change d1. So iter.d1 - iter.key (plus one?) should be the length of the key.



 Comments   
Comment by Kevin Albertson [ 31/Aug/18 ]

Done in CDRIVER-2633.

Comment by A. Jesse Jiryu Davis [ 15/Feb/18 ]

Might optimize C++ driver iterator patterns. Waiting for a prototype with the C++ driver to verify the need.

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