2 Copyright (C) 2009 Equinox Software Inc.
3 Scott McKellar <scott@esilibrary.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
18 @brief Push parser for JSON.
20 This parser provides a way to parse JSON incrementally, without necessarily holding the
21 entire JSON string (or any representation thereof) in memory at once. It can therefore
22 be used, for example, to parse large input files.
26 1. Call jsonNewPushParser() to create a parser, designating a series of callback
27 functions to be called when the parser encounters various syntactic features.
29 2. Pass one or more buffers to jsonPush() for parsing.
31 3. When the last buffer has been parsed, call jsonPushParserFinish() to tell the parser
32 that no more input will be forthcoming.
34 4. Call jsonPushParserFree() to free the parser when you're done with it.
36 By using jsonPushParserReset(), you can reuse a parser for multiple streams, without
37 having to free and recreate it.
39 By using jsonPushParserResume(), you can accept multiple JSON values in the same stream.
40 It is identical to jsonPushParserReset(), except that it does not reset the line number
41 and column number used in error messages.
43 This parser does @em not give any special attention to OSRF-specific conventions for
44 encoding class information.
54 struct JSONPushParserStruct;
55 typedef struct JSONPushParserStruct JSONPushParser;
57 /** @brief A collection of callback pointers */
60 int (*handleString)( void* blob, const char* str );
61 int (*handleNumber)( void* blob, const char* str );
62 int (*handleBeginArray )( void* blob );
63 int (*handleEndArray )( void* blob );
64 int (*handleBeginObj )( void* blob );
65 int (*handleObjKey )( void* blob, const char* key );
66 int (*handleEndObj )( void* blob );
67 int (*handleBool) ( void* blob, int b );
68 int (*handleNull) ( void* blob );
69 void (*handleEndJSON )( void* blob );
70 void (*handleError)( void* blob, const char* msg, unsigned line, unsigned pos );
74 JSONPushParser* jsonNewPushParser( const JSONHandlerMap* map, void* blob );
76 void jsonPushParserReset( JSONPushParser* parser );
78 void jsonPushParserResume( JSONPushParser* parser );
80 int jsonPushParserFinish( JSONPushParser* parser );
82 void jsonPushParserFree( JSONPushParser* parser );
84 int jsonPush( JSONPushParser* parser, const char* str, size_t length );