|
|
@ -41,11 +41,13 @@ static void json_writer_output_char(grpc_json_writer* writer, char c) { |
|
|
|
writer->vtable->output_char(writer->userdata, c); |
|
|
|
writer->vtable->output_char(writer->userdata, c); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void json_writer_output_string(grpc_json_writer* writer, const char* str) { |
|
|
|
static void json_writer_output_string(grpc_json_writer* writer, |
|
|
|
|
|
|
|
const char* str) { |
|
|
|
writer->vtable->output_string(writer->userdata, str); |
|
|
|
writer->vtable->output_string(writer->userdata, str); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void json_writer_output_string_with_len(grpc_json_writer* writer, const char* str, size_t len) { |
|
|
|
static void json_writer_output_string_with_len(grpc_json_writer* writer, |
|
|
|
|
|
|
|
const char* str, size_t len) { |
|
|
|
writer->vtable->output_string_with_len(writer->userdata, str, len); |
|
|
|
writer->vtable->output_string_with_len(writer->userdata, str, len); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -58,8 +60,7 @@ void grpc_json_writer_init(grpc_json_writer* writer, int indent, |
|
|
|
writer->userdata = userdata; |
|
|
|
writer->userdata = userdata; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void json_writer_output_indent( |
|
|
|
static void json_writer_output_indent(grpc_json_writer* writer) { |
|
|
|
grpc_json_writer* writer) { |
|
|
|
|
|
|
|
static const char spacesstr[] = |
|
|
|
static const char spacesstr[] = |
|
|
|
" " |
|
|
|
" " |
|
|
|
" " |
|
|
|
" " |
|
|
@ -99,7 +100,8 @@ static void json_writer_value_end(grpc_json_writer* writer) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void json_writer_escape_utf16(grpc_json_writer* writer, gpr_uint16 utf16) { |
|
|
|
static void json_writer_escape_utf16(grpc_json_writer* writer, |
|
|
|
|
|
|
|
gpr_uint16 utf16) { |
|
|
|
static const char hex[] = "0123456789abcdef"; |
|
|
|
static const char hex[] = "0123456789abcdef"; |
|
|
|
|
|
|
|
|
|
|
|
json_writer_output_string_with_len(writer, "\\u", 2); |
|
|
|
json_writer_output_string_with_len(writer, "\\u", 2); |
|
|
@ -173,8 +175,8 @@ static void json_writer_escape_string(grpc_json_writer* writer, |
|
|
|
* Any other range is technically reserved for future usage, so if we |
|
|
|
* Any other range is technically reserved for future usage, so if we |
|
|
|
* don't want the software to break in the future, we have to allow |
|
|
|
* don't want the software to break in the future, we have to allow |
|
|
|
* anything else. The first non-unicode character is 0x110000. */ |
|
|
|
* anything else. The first non-unicode character is 0x110000. */ |
|
|
|
if (((utf32 >= 0xd800) && (utf32 <= 0xdfff)) || |
|
|
|
if (((utf32 >= 0xd800) && (utf32 <= 0xdfff)) || (utf32 >= 0x110000)) |
|
|
|
(utf32 >= 0x110000)) break; |
|
|
|
break; |
|
|
|
if (utf32 >= 0x10000) { |
|
|
|
if (utf32 >= 0x10000) { |
|
|
|
/* If utf32 contains a character that is above 0xffff, it needs to be
|
|
|
|
/* If utf32 contains a character that is above 0xffff, it needs to be
|
|
|
|
* broken down into a utf-16 surrogate pair. A surrogate pair is first |
|
|
|
* broken down into a utf-16 surrogate pair. A surrogate pair is first |
|
|
@ -194,7 +196,8 @@ static void json_writer_escape_string(grpc_json_writer* writer, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
utf32 -= 0x10000; |
|
|
|
utf32 -= 0x10000; |
|
|
|
json_writer_escape_utf16(writer, (gpr_uint16)(0xd800 | (utf32 >> 10))); |
|
|
|
json_writer_escape_utf16(writer, (gpr_uint16)(0xd800 | (utf32 >> 10))); |
|
|
|
json_writer_escape_utf16(writer, (gpr_uint16)(0xdc00 | (utf32 & 0x3ff))); |
|
|
|
json_writer_escape_utf16(writer, |
|
|
|
|
|
|
|
(gpr_uint16)(0xdc00 | (utf32 & 0x3ff))); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
json_writer_escape_utf16(writer, (gpr_uint16)utf32); |
|
|
|
json_writer_escape_utf16(writer, (gpr_uint16)utf32); |
|
|
|
} |
|
|
|
} |
|
|
@ -204,7 +207,8 @@ static void json_writer_escape_string(grpc_json_writer* writer, |
|
|
|
json_writer_output_char(writer, '"'); |
|
|
|
json_writer_output_char(writer, '"'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_json_writer_container_begins(grpc_json_writer* writer, grpc_json_type type) { |
|
|
|
void grpc_json_writer_container_begins(grpc_json_writer* writer, |
|
|
|
|
|
|
|
grpc_json_type type) { |
|
|
|
if (!writer->got_key) json_writer_value_end(writer); |
|
|
|
if (!writer->got_key) json_writer_value_end(writer); |
|
|
|
json_writer_output_indent(writer); |
|
|
|
json_writer_output_indent(writer); |
|
|
|
json_writer_output_char(writer, type == GRPC_JSON_OBJECT ? '{' : '['); |
|
|
|
json_writer_output_char(writer, type == GRPC_JSON_OBJECT ? '{' : '['); |
|
|
@ -213,7 +217,8 @@ void grpc_json_writer_container_begins(grpc_json_writer* writer, grpc_json_type |
|
|
|
writer->depth++; |
|
|
|
writer->depth++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_json_writer_container_ends(grpc_json_writer* writer, grpc_json_type type) { |
|
|
|
void grpc_json_writer_container_ends(grpc_json_writer* writer, |
|
|
|
|
|
|
|
grpc_json_type type) { |
|
|
|
if (writer->indent && !writer->container_empty) |
|
|
|
if (writer->indent && !writer->container_empty) |
|
|
|
json_writer_output_char(writer, '\n'); |
|
|
|
json_writer_output_char(writer, '\n'); |
|
|
|
writer->depth--; |
|
|
|
writer->depth--; |
|
|
@ -238,14 +243,16 @@ void grpc_json_writer_value_raw(grpc_json_writer* writer, const char* string) { |
|
|
|
writer->got_key = 0; |
|
|
|
writer->got_key = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_json_writer_value_raw_with_len(grpc_json_writer* writer, const char* string, size_t len) { |
|
|
|
void grpc_json_writer_value_raw_with_len(grpc_json_writer* writer, |
|
|
|
|
|
|
|
const char* string, size_t len) { |
|
|
|
if (!writer->got_key) json_writer_value_end(writer); |
|
|
|
if (!writer->got_key) json_writer_value_end(writer); |
|
|
|
json_writer_output_indent(writer); |
|
|
|
json_writer_output_indent(writer); |
|
|
|
json_writer_output_string_with_len(writer, string, len); |
|
|
|
json_writer_output_string_with_len(writer, string, len); |
|
|
|
writer->got_key = 0; |
|
|
|
writer->got_key = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_json_writer_value_string(grpc_json_writer* writer, const char* string) { |
|
|
|
void grpc_json_writer_value_string(grpc_json_writer* writer, |
|
|
|
|
|
|
|
const char* string) { |
|
|
|
if (!writer->got_key) json_writer_value_end(writer); |
|
|
|
if (!writer->got_key) json_writer_value_end(writer); |
|
|
|
json_writer_output_indent(writer); |
|
|
|
json_writer_output_indent(writer); |
|
|
|
json_writer_escape_string(writer, string); |
|
|
|
json_writer_escape_string(writer, string); |
|
|
|