-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
None
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[] =
;
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.