1 /* 2 * Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz> 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _JSON_EVENT_H 6 #define _JSON_EVENT_H 7 8 9 #include <String.h> 10 11 12 /*! This enumeration defines the types of events that may arise when parsing a 13 stream of JSON data. 14 */ 15 16 typedef enum json_event_type { 17 B_JSON_NUMBER = 1, 18 B_JSON_STRING = 2, 19 B_JSON_TRUE = 3, 20 B_JSON_FALSE = 4, 21 B_JSON_NULL = 5, 22 B_JSON_OBJECT_START = 6, 23 B_JSON_OBJECT_END = 7, 24 B_JSON_OBJECT_NAME = 8, // aka field 25 B_JSON_ARRAY_START = 9, 26 B_JSON_ARRAY_END = 10 27 } json_event_type; 28 29 30 namespace BPrivate { 31 32 class BJsonEvent { 33 public: 34 BJsonEvent(json_event_type eventType, 35 const char* content); 36 BJsonEvent(const char* content); 37 BJsonEvent(double content); 38 BJsonEvent(int64 content); 39 BJsonEvent(json_event_type eventType); 40 ~BJsonEvent(); 41 42 json_event_type EventType() const; 43 44 const char* Content() const; 45 double ContentDouble() const; 46 int64 ContentInteger() const; 47 48 private: 49 50 json_event_type fEventType; 51 const char* fContent; 52 char* fOwnedContent; 53 }; 54 55 } // namespace BPrivate 56 57 using BPrivate::BJsonEvent; 58 59 #endif // _JSON_EVENT_H 60