4 ** Handlers that emit JSON according to a specific protobuf schema.
7 #ifndef UPB_JSON_TYPED_PRINTER_H_
8 #define UPB_JSON_TYPED_PRINTER_H_
16 } /* namespace json */
20 /* upb_json_printer ***********************************************************/
22 #define UPB_JSON_PRINTER_SIZE 192
24 struct upb_json_printer;
25 typedef struct upb_json_printer upb_json_printer;
32 upb_json_printer *upb_json_printer_create(upb_arena *a, const upb_handlers *h,
33 upb_bytessink output);
34 upb_sink upb_json_printer_input(upb_json_printer *p);
35 const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
36 bool preserve_fieldnames,
39 /* Lazily builds and caches handlers that will push encoded data to a bytessink.
40 * Any msgdef objects used with this object must outlive it. */
41 upb_handlercache *upb_json_printer_newcache(bool preserve_proto_fieldnames);
46 /* Prints an incoming stream of data to a BytesSink in JSON format. */
47 class upb::json::PrinterPtr {
49 PrinterPtr(upb_json_printer* ptr) : ptr_(ptr) {}
51 static PrinterPtr Create(Arena *arena, const upb::Handlers *handlers,
54 upb_json_printer_create(arena->ptr(), handlers, output.sink()));
57 /* The input to the printer. */
58 Sink input() { return upb_json_printer_input(ptr_); }
60 static const size_t kSize = UPB_JSON_PRINTER_SIZE;
62 static HandlerCache NewCache(bool preserve_proto_fieldnames) {
63 return upb_json_printer_newcache(preserve_proto_fieldnames);
67 upb_json_printer* ptr_;
70 #endif /* __cplusplus */
72 #endif /* UPB_JSON_TYPED_PRINTER_H_ */