diff options
author | Chris Fallin <cfallin@c1f.net> | 2015-02-02 13:38:05 -0800 |
---|---|---|
committer | Chris Fallin <cfallin@c1f.net> | 2015-02-02 13:38:05 -0800 |
commit | fb585045692c482b6946fff63f0cd8425c8c70b5 (patch) | |
tree | 5ea54a02a338f2123503f840280a6e037cd65954 /upb/json/parser.h | |
parent | 51513c6e7f9df3f04fde0ff94bfe654f8dccaaa0 (diff) |
Support maps in JSON parsing and serialization.
This is a sync of our internal developing of JSON parsing and
serialization. It implements native understanding of MapEntry
submessages, so that map fields with (key, value) pairs are serialized
as JSON maps (objects) natively rather than as arrays of objects with
'key' and 'value' fields. The parser also now understands how to emit
handler calls corresponding to MapEntry objects when processing a map
field.
This sync also picks up a bugfix in `table.c` to handle an alloc-failed
case.
Diffstat (limited to 'upb/json/parser.h')
-rw-r--r-- | upb/json/parser.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/upb/json/parser.h b/upb/json/parser.h index 51578f2..c693edf 100644 --- a/upb/json/parser.h +++ b/upb/json/parser.h @@ -23,12 +23,30 @@ class Parser; UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser); -// Internal-only struct used by the parser. +// Internal-only struct used by the parser. A parser frame corresponds +// one-to-one with a handler (sink) frame. typedef struct { UPB_PRIVATE_FOR_CPP upb_sink sink; + // The current message in which we're parsing, and the field whose value we're + // expecting next. const upb_msgdef *m; const upb_fielddef *f; + + // We are in a repeated-field context, ready to emit mapentries as + // submessages. This flag alters the start-of-object (open-brace) behavior to + // begin a sequence of mapentry messages rather than a single submessage. + bool is_map; + // We are in a map-entry message context. This flag is set when parsing the + // value field of a single map entry and indicates to all value-field parsers + // (subobjects, strings, numbers, and bools) that the map-entry submessage + // should end as soon as the value is parsed. + bool is_mapentry; + // If |is_map| or |is_mapentry| is true, |mapfield| refers to the parent + // message's map field that we're currently parsing. This differs from |f| + // because |f| is the field in the *current* message (i.e., the map-entry + // message itself), not the parent's field that leads to this map. + const upb_fielddef *mapfield; } upb_jsonparser_frame; |