GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
json.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #ifndef GRPC_INTERNAL_CORE_JSON_JSON_H
35 #define GRPC_INTERNAL_CORE_JSON_JSON_H
36
37 #include <stdlib.h>
38
39 #include "src/core/json/json_common.h"
40
41 /* A tree-like structure to hold json values. The key and value pointers
42 * are not owned by it.
43 */
44 typedef struct grpc_json {
45 struct grpc_json* next;
46 struct grpc_json* prev;
47 struct grpc_json* child;
48 struct grpc_json* parent;
49
50 grpc_json_type type;
51 const char* key;
52 const char* value;
53 } grpc_json;
54
55 /* The next two functions are going to parse the input string, and
56 * modify it in the process, in order to use its space to store
57 * all of the keys and values for the returned object tree.
58 *
59 * They assume UTF-8 input stream, and will output UTF-8 encoded
60 * strings in the tree. The input stream's UTF-8 isn't validated,
61 * as in, what you input is what you get as an output.
62 *
63 * All the keys and values in the grpc_json objects will be strings
64 * pointing at your input buffer.
65 *
66 * Delete the allocated tree afterward using grpc_json_destroy().
67 */
68 grpc_json* grpc_json_parse_string_with_len(char* input, size_t size);
69 grpc_json* grpc_json_parse_string(char* input);
70
71 /* This function will create a new string using gpr_realloc, and will
72 * deserialize the grpc_json tree into it. It'll be zero-terminated,
73 * but will be allocated in chunks of 256 bytes.
74 *
75 * The indent parameter controls the way the output is formatted.
76 * If indent is 0, then newlines will be suppressed as well, and the
77 * output will be condensed at its maximum.
78 */
79 char* grpc_json_dump_to_string(grpc_json* json, int indent);
80
81 /* Use these to create or delete a grpc_json object.
82 * Deletion is recursive. We will not attempt to free any of the strings
83 * in any of the objects of that tree.
84 */
85 grpc_json* grpc_json_create(grpc_json_type type);
86 void grpc_json_destroy(grpc_json* json);
87
88 #endif /* GRPC_INTERNAL_CORE_JSON_JSON_H */
grpc_json_parse_string_with_len
grpc_json * grpc_json_parse_string_with_len(char *input, size_t size)
Definition: json_string.c:305
grpc_json::key
const char * key
Definition: json.h:51
json_common.h
grpc_json::type
grpc_json_type type
Definition: json.h:50
grpc_json_type
grpc_json_type
Definition: json_common.h:38
grpc_json_parse_string
grpc_json * grpc_json_parse_string(char *input)
Definition: json_string.c:332
grpc_json::child
struct grpc_json * child
Definition: json.h:47
grpc_json_dump_to_string
char * grpc_json_dump_to_string(grpc_json *json, int indent)
Definition: json_string.c:378
grpc_json::value
const char * value
Definition: json.h:52
grpc_json::next
struct grpc_json * next
Definition: json.h:45
grpc_json
Definition: json.h:44
grpc_json
struct grpc_json grpc_json
grpc_json::parent
struct grpc_json * parent
Definition: json.h:48
grpc_json_create
grpc_json * grpc_json_create(grpc_json_type type)
Definition: json.c:40
grpc_json::prev
struct grpc_json * prev
Definition: json.h:46
grpc_json_destroy
void grpc_json_destroy(grpc_json *json)
Definition: json.c:48