@@ -123,6 +123,7 @@ struct ParsedJson {
123123 // print the json to stdout (should be valid)
124124 // return false if the tape is likely wrong (e.g., you did not parse a valid
125125 // JSON).
126+ WARN_UNUSED
126127 bool printjson () {
127128 size_t tapeidx = 0 ;
128129 u64 tape_val = tape[tapeidx];
@@ -224,6 +225,73 @@ struct ParsedJson {
224225 return true ;
225226 }
226227
228+ bool dump_raw_tape () {
229+ size_t tapeidx = 0 ;
230+ u64 tape_val = tape[tapeidx++];
231+ u8 type = (tape_val >> 56 );
232+ size_t howmany = 0 ;
233+ if (type == ' r' ) {
234+ howmany = tape_val & JSONVALUEMASK ;
235+ } else {
236+ printf (" Error: no starting root node?" );
237+ return false ;
238+ }
239+ for (; tapeidx < howmany; tapeidx++) {
240+ tape_val = tape[tapeidx];
241+ u64 payload = tape_val & JSONVALUEMASK ;
242+ type = (tape_val >> 56 );
243+ switch (type) {
244+ case ' "' : // we have a string
245+ printf (" string: " );
246+ putchar (' "' );
247+ print_with_escapes ((const unsigned char *)(string_buf + payload));
248+ putchar (' "' );
249+ printf (" \n " );
250+ break ;
251+ case ' l' : // we have a long int
252+ if (tapeidx + 1 >= howmany)
253+ return false ;
254+ printf (" integer: " );
255+ printf (" %" PRId64, (int64_t )tape[++tapeidx]);
256+ break ;
257+ case ' d' : // we have a double
258+ printf (" float: " );
259+ if (tapeidx + 1 >= howmany)
260+ return false ;
261+ printf (" %f" , *((double *)&tape[++tapeidx]));
262+ break ;
263+ case ' n' : // we have a null
264+ printf (" null" );
265+ break ;
266+ case ' t' : // we have a true
267+ printf (" true" );
268+ break ;
269+ case ' f' : // we have a false
270+ printf (" false" );
271+ break ;
272+ case ' {' : // we have an object
273+ printf (" {" );
274+ break ;
275+ case ' }' : // we end an object
276+ printf (" }" );
277+ break ;
278+ case ' [' : // we start an array
279+ printf (" [" );
280+ break ;
281+ case ' ]' : // we end an array
282+ printf (" ]" );
283+ break ;
284+ case ' r' : // we start and end with the root node
285+ printf (" end of root" );
286+ return false ;
287+ default :
288+ return false ;
289+ }
290+ }
291+ return true ;
292+ }
293+
294+
227295 // all elements are stored on the tape using a 64-bit word.
228296 //
229297 // strings, double and ints are stored as
0 commit comments