summaryrefslogtreecommitdiff
path: root/upb/json/printer.h
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2016-04-14 16:28:47 -0700
committerJoshua Haberman <jhaberman@gmail.com>2016-04-14 16:28:47 -0700
commit89197b9358c127e41dd9f428578783ec09a94d82 (patch)
treea970d947ecfd7dba9df92b92982ae08d5f2dd9a2 /upb/json/printer.h
parent534b5c98baf02b2101d25917d46a1605906a6c53 (diff)
JSON parser: always accept both name variants, flag controls which we generate.
* JSON parser: always accept both name variants, flag controls which we generate. My previous commit was based on wrong information about the proto3 JSON spec. It turns out we need to accept both field name formats all the time, and a runtime flag should control which we generate. * Documented the preserve_proto_fieldnames option. * Fix bugs in PR.
Diffstat (limited to 'upb/json/printer.h')
-rw-r--r--upb/json/printer.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/upb/json/printer.h b/upb/json/printer.h
index 84d814c..36a24e9 100644
--- a/upb/json/printer.h
+++ b/upb/json/printer.h
@@ -36,8 +36,12 @@ class upb::json::Printer {
/* The input to the printer. */
Sink* input();
- /* Returns handlers for printing according to the specified schema. */
- static reffed_ptr<const Handlers> NewHandlers(const upb::MessageDef* md);
+ /* Returns handlers for printing according to the specified schema.
+ * If preserve_proto_fieldnames is true, the output JSON will use the
+ * original .proto field names (ie. {"my_field":3}) instead of using
+ * camelCased names, which is the default: (eg. {"myField":3}). */
+ static reffed_ptr<const Handlers> NewHandlers(const upb::MessageDef* md,
+ bool preserve_proto_fieldnames);
static const size_t kSize = UPB_JSON_PRINTER_SIZE;
@@ -54,6 +58,7 @@ upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h,
upb_bytessink *output);
upb_sink *upb_json_printer_input(upb_json_printer *p);
const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
+ bool preserve_fieldnames,
const void *owner);
UPB_END_EXTERN_C
@@ -68,8 +73,9 @@ inline Printer* Printer::Create(Environment* env, const upb::Handlers* handlers,
}
inline Sink* Printer::input() { return upb_json_printer_input(this); }
inline reffed_ptr<const Handlers> Printer::NewHandlers(
- const upb::MessageDef *md) {
- const Handlers* h = upb_json_printer_newhandlers(md, &h);
+ const upb::MessageDef *md, bool preserve_proto_fieldnames) {
+ const Handlers* h = upb_json_printer_newhandlers(
+ md, preserve_proto_fieldnames, &h);
return reffed_ptr<const Handlers>(h, &h);
}
} /* namespace json */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback