2 * A general structure for extracting hierarchical data from the devices;
3 * typically key-value pairs, but allows for more rich data as well
5 * Copyright (C) 2015 by Erkki Seppälä <flux@modeemi.fi>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 data_t *data = data_make("label" , "", DATA_STRING, "1.2.3",
28 "house_code" , "House Code", DATA_INT, 42,
29 "temp" , "Temperature", DATA_DOUBLE, 99.9,
30 "array" , "Array", DATA_ARRAY, data_array(2, DATA_STRING, (char*[2]){"hello", "world"}),
31 "array2" , "Array 2", DATA_ARRAY, data_array(2, DATA_INT, (int[2]){4, 2}),
32 "array3" , "Array 3", DATA_ARRAY, data_array(2, DATA_ARRAY, (data_array_t*[2]){
33 data_array(2, DATA_INT, (int[2]){4, 2}),
34 data_array(2, DATA_INT, (int[2]){5, 5}) }),
35 "data" , "Data", DATA_DATA, data_make("Hello", "hello", DATA_STRING, "world", NULL),
37 const char *fields[] = { "label", "house_code", "temp", "array", "array2", "array3", "data", "house_code" };
38 data_print(data, stdout, &data_json_printer, NULL); fprintf(stdout, "\n");
39 data_print(data, stdout, &data_kv_printer, NULL);
40 void *csv_aux = data_csv_init(fields, sizeof fields / sizeof *fields);
41 data_print(data, stdout, &data_csv_printer, csv_aux);
42 data_csv_free(csv_aux);