Json Types¶
Standard Data Types¶
The primitive data types of all tree nodes are derived from the JSON standard, together with a few small extensions. JSON defines the following types:
- Null
This is a special type consisting only of the value null. It is used for uninitialized or inexistent elements.
- Boolean
This type is for boolean values, valid elements are
true
andfalse
.- Number
This type is for numbers. This type does not distinguish between floating point numbers and integers. Possible values are for example
4
,123
,1.23e2
or-12.3
. NxLib functions for reading integers effectively return the rounded value if it is not integer.- String
Contains a sequence of characters. Special characters need to be escaped properly. Possible values are for example
"Hello World!"
,"This\nis\nline three."
or"Nested \"quotes\" look like that."
. Please refer to http://www.json.org for escaping rules.- Array
An array contains other elements of arbitrary JSON types. It is especially important to note that every element can have a different type. Array elements in NxLib are accessed via their integer index, starting at zero. Arrays are surrounded by square brackets, values are separated by a comma. Example values are
[1, 2, 3]
or[1, 2.4, "Hello", ["a","b"]]
.- Object
An object also contains subelements, but in contrast to arrays each element is identified by a string instead of an index. Objects are surounded by curly braces and consist of
key:value
pairs, separated by commas. Examples are{"name":{"family":"Duesentrieb","given":"Daniel"}, "age":45,"profession":"inventor"}
or{"weather":"good", "points":[[1,2], [0,4], [-4,7]]}
.
If you have never seen JSON, we encourage you to take a quick look at some examples on one of these pages:
http://en.wikipedia.org/wiki/JSON for an introduction with some examples.
http://www.json.org/ for a more formal specification. There are also many open source parsers and helper libraries listed here.
Proprietary Extensions¶
There are currently two extensions to these types:
- Link
Link nodes are nodes of type String, but an internal flag on the node indicates that its string content is a path to another item. The library then transparently makes the content of the node it refers to available at this node. This technique is used to make cameras available under their EEPROM ID, by linking to the node of the corresponding camera serial number.
- Binary
Binary nodes are used to publish images or point clouds. A binary blob is a node of the basic type Number, to which a memory block is associated. The node’s number value corresponds to its revision in form of a time stamp. Special accessor functions allow to query the exact size and format of the memory block and get a copy of its content written to a user specified memory location.
Note
Binary node timestamps indicate the number of seconds elapsed since January 1st, 1601 (UTC). The example below illustrates how to convert a time stamp into a
SYSTEMTIME
struct on Windows.
Conversion of Binary Node Timestamps¶
double timestamp;
nxLibGetBinaryInfo(..., ×tamp);
__int64 fileTimeAsInt = (__int64) (timestamp*1e7); // Convert seconds to 1/10 microseconds
FILETIME fileTime;
fileTime.dwLowDateTime = (unsigned int) fileTimeAsInt; // write int64 into low and high part of FILETIME struct
fileTime.dwHighDateTime = (unsigned int) (fileTimeAsInt >> 32);
SYSTEMTIME utcTime;
if (FileTimeToSystemTime(&fileTime, &utcTime)) {
printf("Time stamp is %d-%d-%d %02d:%02d:%02d.%03d", utcTime.wYear, utcTime.wMonth, utcTime.wDay, utcTime.wHour, utcTime.wMinute, utcTime.wSecond, utcTime.wMilliseconds);
}
Note
On Linux operating systems, timestamps usually refer to January 1st, 1970 (UTC). The offset between the two representations is fixed to 11644473600.0 seconds.