Fix: update the correct pre-built script to cmake-sonar.sh
[ric-app/mc.git] / schemaparser / sample2.cc
1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4
5 #include<string>
6 #include<iostream>
7 #include<fstream>
8
9 #include"schemaparser.h"
10
11 struct vstring32 {
12     unsigned int length;
13     unsigned int offset;
14     unsigned int reserved;
15 };
16
17
18 struct thpt{
19         unsigned long long int TS;
20         unsigned long long int e_RAB_ID;
21         unsigned long long int UE_ID;
22         vstring32 GNB_ID;
23         double measurement_interval;
24         unsigned long long int active_throughput;
25         unsigned long long int average_throughput;
26         unsigned long long int min_throughput;
27         unsigned long long int max_throughput;
28 };
29         
30
31 using namespace std;
32 using namespace mc_schema;
33
34 int main(int argc, char **argv){
35 //              Get the nib.json file
36         string directory = ".";
37         if(argc>1){
38                 directory = argv[1];
39         }
40         string inflnm = directory + "/" + string("nib.json");
41
42         ifstream infl(inflnm);
43         if(!infl){
44                 cerr << "Error, can't open " << inflnm << endl;
45                 exit(1);
46         }
47         string line;
48         string nib_str;
49         while(getline(infl, line)){
50                 nib_str += line;
51         }
52         infl.close();
53
54 //              Load the schemas
55         mc_schemas *mcs = new_mc_schemas(nib_str);
56         if(mcs->has_errors()){
57                 fprintf(stderr, "Errors loading the schemas:\n%s\n",mcs->get_errors().c_str());
58         }else{
59                 vector<string> streams = mcs->get_streams();
60                 printf("Loaded %ld streams:\n", streams.size());
61                 for(int i=0;i<streams.size(); ++i){
62                         string str_rep = mcs->get_query_rep(streams[i])->to_string();
63                         printf("\t%s\n",str_rep.c_str());
64                 }
65         }
66
67 //              Load a sample record
68         char buf[150];
69         thpt *t = (thpt *)buf;
70         t->TS = 10001;
71         t->e_RAB_ID = 2;
72         t->UE_ID = 3;
73
74         t->GNB_ID.length = 6;
75         t->GNB_ID.offset = sizeof(thpt);
76         string foobar("foobar");
77         strncpy(buf+sizeof(thpt), foobar.c_str(), 6);
78
79         t->measurement_interval = 10.1;
80         t->active_throughput = 4;
81         t->average_throughput = 5;
82         t->min_throughput = 6;
83         t->max_throughput = 7;
84
85         int t_len = sizeof(thpt)+6;
86         
87 //              Get the throughput_ue schema
88         query_rep *qr = mcs->get_query_rep("throughput_ue");
89
90 //              Extract stuff by various methods
91         int ts_idx = qr->get_index_of_field("TS");
92         int ts_type = qr->get_type(ts_idx);
93         int ts_offset = qr->get_offset(ts_idx);
94         field_handle ts_handle = qr->get_handle(ts_idx);
95
96         string ts_s = get_field_string(ts_handle, buf, t_len);
97         unsigned long long int ts_lu = get_field_ullong(ts_handle, buf, t_len);
98         unsigned int ts_u = get_field_uint(ts_handle, buf, t_len);
99         printf("ts string=%s, ullong=%lld, uint = %d\n",ts_s.c_str(), ts_lu, ts_u);
100
101         field_handle erab_handle = qr->get_handle(1);
102         access_result erab_ar = get_field_by_handle(erab_handle, buf, t_len);
103         printf("erab = %lld\n", erab_ar.r.l);
104
105         access_result ue_ar = get_field_by_index(qr, 2, buf, t_len);
106         printf("ue = %lld\n", ue_ar.r.l);
107
108         int gnb_idx = qr->get_index_of_field("GNB_ID");
109         field_handle gnb_handle = qr->get_handle(gnb_idx);
110         string gnb = get_field_string(gnb_handle, buf, t_len);
111         printf("gnb=%s\n",gnb.c_str());
112
113         access_result mt_ar = get_field_by_index(qr, 8, buf, t_len);
114         printf("mt = %lld, type=%d\n", mt_ar.r.l, mt_ar.field_data_type);
115
116         access_result none_ar = get_field_by_index(qr, 9, buf, t_len);
117         printf("none = %lld, type=%d\n", none_ar.r.l, none_ar.field_data_type);
118
119 }