[CDRIVER-164] BCON (BSON C Object Notation) C initializers for BSON Created: 01/Aug/12  Updated: 19/Oct/16  Resolved: 01/Aug/12

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

Type: Improvement Priority: Minor - P4
Reporter: Gary Murakami Assignee: Gary Murakami
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

BCON provides for JSON-like (or BSON-like) initializers in C.
Without this, BSON must be constructed by procedural coding via explicit function calls.
With this, you now have convenient data-driven definition of BSON documents.
Here are a couple of introductory examples.

bcon hello[] =

{ "hello", "world", "." }

;
bcon pi[] =

{ "pi", BF(3.14159), BEND }

;
BCON is an array of bcon union elements with the default type of cstring (char *).
A BCON document must be terminated with a cstring containing a single dot, i.e., ".", or the macro equivalent BEND.

Cstring literals in double quotes are used for keys as well as for string values.
There is no explicit colon (':') separator between key and value, just a comma,
however it must be explicit or C will quietly concatenate the key and value strings for you.
Readability may be improved by using multiple lines with a key-value pair per line.

Macros are used to enclose specific types, and an internal type-specifier string prefixes a typed value.
Macros are also used to specify interpolation of values from pointers to specified types.

Sub-documents are framed by "

{" "}

" string literals, and sub-arrays are framed by "[" "]" literals.

All of this is needed because C arrays and initializers are mono-typed unlike dict/array types in modern languages.
BCON attempts to be readable and JSON-like within the context and restrictions of the C language.



 Comments   
Comment by auto [ 01/Aug/12 ]

Author:

{u'date': u'2012-08-01T07:40:56-07:00', u'email': u'gary.murakami@10gen.com', u'name': u'Gary Murakami'}

Message: CDRIVER-164 - BCON (BSON C Object Notation) C initializers for BSON
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/dc70faf4a02031515c4cd49e03205431729b4017

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