From f9afc3e55bbc289df41606d493377318c6645817 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Wed, 13 Jan 2016 18:04:48 -0800 Subject: Changed JSON parser/printer to correctly camelCase names. --- upb/json/parser.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) (limited to 'upb/json/parser.h') diff --git a/upb/json/parser.h b/upb/json/parser.h index e8f34fe..1d67dc4 100644 --- a/upb/json/parser.h +++ b/upb/json/parser.h @@ -15,11 +15,14 @@ namespace upb { namespace json { class Parser; +class ParserMethod; } /* namespace json */ } /* namespace upb */ #endif UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser) +UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted, + upb_json_parsermethod, upb_refcounted) /* upb::json::Parser **********************************************************/ @@ -27,7 +30,7 @@ UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser) * constructed. This hint may be an overestimate for some build configurations. * But if the parser library is upgraded without recompiling the application, * it may be an underestimate. */ -#define UPB_JSON_PARSER_SIZE 3704 +#define UPB_JSON_PARSER_SIZE 4104 #ifdef __cplusplus @@ -35,7 +38,8 @@ UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser) * sink. */ class upb::json::Parser { public: - static Parser* Create(Environment* env, Sink* output); + static Parser* Create(Environment* env, const ParserMethod* method, + Sink* output); BytesSink* input(); @@ -43,25 +47,72 @@ class upb::json::Parser { UPB_DISALLOW_POD_OPS(Parser, upb::json::Parser) }; +class upb::json::ParserMethod { + public: + /* Include base methods from upb::ReferenceCounted. */ + UPB_REFCOUNTED_CPPMETHODS + + /* Returns handlers for parsing according to the specified schema. */ + static reffed_ptr New(const upb::MessageDef* md); + + /* The destination handlers that are statically bound to this method. + * This method is only capable of outputting to a sink that uses these + * handlers. */ + const Handlers* dest_handlers() const; + + /* The input handlers for this decoder method. */ + const BytesHandler* input_handler() const; + + private: + UPB_DISALLOW_POD_OPS(ParserMethod, upb::json::ParserMethod) +}; + #endif UPB_BEGIN_EXTERN_C -upb_json_parser *upb_json_parser_create(upb_env *e, upb_sink *output); +upb_json_parser* upb_json_parser_create(upb_env* e, + const upb_json_parsermethod* m, + upb_sink* output); upb_bytessink *upb_json_parser_input(upb_json_parser *p); +upb_json_parsermethod* upb_json_parsermethod_new(const upb_msgdef* md, + const void* owner); +const upb_handlers *upb_json_parsermethod_desthandlers( + const upb_json_parsermethod *m); +const upb_byteshandler *upb_json_parsermethod_inputhandler( + const upb_json_parsermethod *m); + +/* Include refcounted methods like upb_json_parsermethod_ref(). */ +UPB_REFCOUNTED_CMETHODS(upb_json_parsermethod, upb_json_parsermethod_upcast) + UPB_END_EXTERN_C #ifdef __cplusplus namespace upb { namespace json { -inline Parser* Parser::Create(Environment* env, Sink* output) { - return upb_json_parser_create(env, output); +inline Parser* Parser::Create(Environment* env, const ParserMethod* method, + Sink* output) { + return upb_json_parser_create(env, method, output); } inline BytesSink* Parser::input() { return upb_json_parser_input(this); } + +inline const Handlers* ParserMethod::dest_handlers() const { + return upb_json_parsermethod_desthandlers(this); +} +inline const BytesHandler* ParserMethod::input_handler() const { + return upb_json_parsermethod_inputhandler(this); +} +/* static */ +inline reffed_ptr ParserMethod::New( + const MessageDef* md) { + const upb_json_parsermethod *m = upb_json_parsermethod_new(md, &m); + return reffed_ptr(m, &m); +} + } /* namespace json */ } /* namespace upb */ -- cgit v1.2.3