AppDynamics IoT C++ SDK
AppDynamics IoT C++ library contains code that facilitates capturing availability, usage, network performance and errors of an IoT Application.
json_serializer.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 AppDynamics, Inc., and its affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef _JSON_SERIALIZER_HPP
19 #define _JSON_SERIALIZER_HPP
20 #include "appd_iot_interface.h"
21 
25 typedef enum
26 {
34 } json_ops_t;
35 
39 typedef struct
40 {
41  size_t len;
42  size_t max_len;
43  char* buf;
44  char* printbuf;
46 } json_t;
47 
53 
61 appd_iot_error_code_t appd_iot_json_start_array(json_t* json, const char* array_name);
62 
70 appd_iot_error_code_t appd_iot_json_start_object(json_t* json, const char* object_name);
71 
78 
85 
94 (json_t* json, const char* key, const char* strval);
95 
103 appd_iot_error_code_t appd_iot_json_add_integer_key_value(json_t* json, const char* key, int64_t intval);
104 
112 appd_iot_error_code_t appd_iot_json_add_double_key_value(json_t* json, const char* key, double doubleval);
113 
121 appd_iot_error_code_t appd_iot_json_add_boolean_key_value(json_t* json, const char* key, bool boolval);
122 
130 
138 
146 
154 
160 const char* appd_iot_json_get_string(json_t* json);
161 
167 const char* appd_iot_json_pretty_print(json_t* json);
168 
173 void appd_iot_json_free(json_t* json);
174 
175 #endif // _JSON_SERIALIZER_HPP
176 
char * printbuf
Definition: json_serializer.hpp:44
char * buf
Definition: json_serializer.hpp:43
appd_iot_error_code_t appd_iot_json_add_integer_value(json_t *json, int64_t intval)
adds value to json object. This function is typically used to add integer values to JSON arrays ...
Definition: json_serializer.cpp:592
appd_iot_error_code_t appd_iot_json_start_array(json_t *json, const char *array_name)
starts json array by adding char '[' to json buf. If a name is given it will be "name":[ ...
Definition: json_serializer.cpp:147
json_t * appd_iot_json_init(void)
Creates, Initializes and returns a new json struct.
Definition: json_serializer.cpp:49
const char * appd_iot_json_pretty_print(json_t *json)
format and returns json string with line breaks, indentiation at start/end of objects/arrays ...
Definition: json_serializer.cpp:634
size_t len
Definition: json_serializer.hpp:41
Definition: json_serializer.hpp:30
appd_iot_error_code_t appd_iot_json_add_string_value(json_t *json, const char *value)
adds value to json object. This function is typically used to add string values to JSON arrays ...
Definition: json_serializer.cpp:580
appd_iot_error_code_t appd_iot_json_end_object(json_t *json)
ends json object by adding char '}' to json buf.
Definition: json_serializer.cpp:210
size_t max_len
Definition: json_serializer.hpp:42
Definition: json_serializer.hpp:28
appd_iot_error_code_t
Error Code Enums for SDK log.
Definition: appd_iot_def.h:27
appd_iot_error_code_t appd_iot_json_add_double_key_value(json_t *json, const char *key, double doubleval)
adds key:value pair to json object with value as double
Definition: json_serializer.cpp:460
Definition: json_serializer.hpp:33
appd_iot_error_code_t appd_iot_json_add_boolean_key_value(json_t *json, const char *key, bool boolval)
adds key:value pair to json object with value as boolean
Definition: json_serializer.cpp:472
Definition: json_serializer.hpp:29
Definition: json_serializer.hpp:31
appd_iot_error_code_t appd_iot_json_add_integer_key_value(json_t *json, const char *key, int64_t intval)
adds key:value pair to json object with value as 64 bit integer
Definition: json_serializer.cpp:451
const char * appd_iot_json_get_string(json_t *json)
returns the json string constructed so far.
Definition: json_serializer.cpp:624
void appd_iot_json_free(json_t *json)
frees json structure
Definition: json_serializer.cpp:731
appd_iot_error_code_t appd_iot_json_add_string_key_value(json_t *json, const char *key, const char *strval)
adds key:value pair to json object with value as string
Definition: json_serializer.cpp:438
json_ops_t last_op
Definition: json_serializer.hpp:45
Definition: json_serializer.hpp:27
appd_iot_error_code_t appd_iot_json_start_object(json_t *json, const char *object_name)
starts json object by adding char '{' to json buf. If a name is given it will be "name":{ ...
Definition: json_serializer.cpp:159
Definition: json_serializer.hpp:32
appd_iot_error_code_t appd_iot_json_add_double_value(json_t *json, double doubleval)
adds value to json object. This function is typically used to add double values to JSON arrays ...
Definition: json_serializer.cpp:603
appd_iot_error_code_t appd_iot_json_end_array(json_t *json)
ends json object by adding char ']' to json buf.
Definition: json_serializer.cpp:220
appd_iot_error_code_t appd_iot_json_add_boolean_value(json_t *json, bool boolval)
adds value to json object. This function is typically used to add boolean values to JSON arrays ...
Definition: json_serializer.cpp:614
JSON struct which holds json string in a buffer.
Definition: json_serializer.hpp:39
json_ops_t
Enums to keep track of last JSON Operation completed.
Definition: json_serializer.hpp:25