forked from merbanan/rtl_433
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-test.c
54 lines (47 loc) · 2.14 KB
/
data-test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* A general structure for extracting hierarchical data from the devices;
* typically key-value pairs, but allows for more rich data as well
*
* Copyright (C) 2015 by Erkki Seppälä <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "data.h"
#include "output_file.h"
int main()
{
data_t *data = data_make("label" , "", DATA_STRING, "1.2.3",
"house_code" , "House Code", DATA_INT, 42,
"temp" , "Temperature", DATA_DOUBLE, 99.9,
"array" , "Array", DATA_ARRAY, data_array(2, DATA_STRING, (char*[2]){"hello", "world"}),
"array2" , "Array 2", DATA_ARRAY, data_array(2, DATA_INT, (int[2]){4, 2}),
"array3" , "Array 3", DATA_ARRAY, data_array(2, DATA_ARRAY, (data_array_t*[2]){
data_array(2, DATA_INT, (int[2]){4, 2}),
data_array(2, DATA_INT, (int[2]){5, 5}) }),
"data" , "Data", DATA_DATA, data_make("Hello", "hello", DATA_STRING, "world", NULL),
NULL);
const char *fields[] = { "label", "house_code", "temp", "array", "array2", "array3", "data", "house_code" };
void *json_output = data_output_json_create(stdout);
void *kv_output = data_output_kv_create(stdout);
void *csv_output = data_output_csv_create(stdout);
data_output_start(csv_output, fields, sizeof fields / sizeof *fields);
data_output_print(json_output, data); fprintf(stdout, "\n");
data_output_print(kv_output, data);
data_output_print(csv_output, data);
data_output_free(json_output);
data_output_free(kv_output);
data_output_free(csv_output);
data_free(data);
}