OMBSON
This libraries is used to convert string based JSON to binary based JSON (known as BSON). BSON is most commonly used in MongoDB to store data. Text in a JSON string are converted to their ASCII value and stored in order in a USINT array.
json2bson()
Direction | Name | Type | Description |
---|---|---|---|
In | Bin | UDINT | This UDINT will be the address of the BSON Output after the function is called. The BSON output is a USINT array. |
In | Str | UDINT | This UDINT is the address of the Json string to be converted. |
In | BufferSize | UDINT | This is the siz of the BSON output. |
Usage
After convert is set high, the JSON string declared in the init will be converted to BSON and stored in the BSON array.
void _INIT ProgramInit(void)
{
brsstrcpy(&Json, "{\"request\": \"Convert to BSON\"}");
}
void _CYCLIC ProgramCyclic(void)
{
if (convert){
convert = 0;
//Bson is declared as USINT[0..40]
json2bson(&Bson, &Json, sizeof(Bson));
}
// After conversion
// Bson[40] = 34, 0, 0, 0, 2, 114, 101, 113, 117, 101, 115, 116, 0, 16, 0, 0, 0, 67, 111, 110, 118, 101, 114, 116, 32, 116, 111, 32, 66, 83, 79, 78, 0, 0, 0, 0, 0, 0, 0, 0
}