@@ -317,11 +317,80 @@ enum CborParserIteratorFlags
317
317
};
318
318
319
319
struct CborValue ;
320
+
321
+ /**
322
+ * Defines an interface for abstract document readers. This structure is used
323
+ * in conjunction with \ref cbor_parser_init_reader to define how the various
324
+ * required operations are to be implemented.
325
+ */
320
326
struct CborParserOperations
321
327
{
328
+ /**
329
+ * Determines whether \a len bytes may be read from the reader. This is
330
+ * called before \ref read_bytes and \ref transfer_bytes to ensure it is safe
331
+ * to read the requested number of bytes from the reader.
332
+ *
333
+ * \param token An opaque object passed to \ref cbor_parser_init_reader
334
+ * that may be used to pass context information between the
335
+ * \ref CborParserOperations methods.
336
+ *
337
+ * \param len The number of bytes sought.
338
+ *
339
+ * \retval true \a len bytes may be read from the reader.
340
+ * \retval false Insufficient data is available to be read at this time.
341
+ */
322
342
bool (* can_read_bytes )(void * token , size_t len );
343
+
344
+ /**
345
+ * Reads \a len bytes from the reader starting at \a offset bytes from
346
+ * the current read position and copies them to \a dst. The read pointer
347
+ * is *NOT* modified by this operation.
348
+ *
349
+ * \param token An opaque object passed to \ref cbor_parser_init_reader
350
+ * that may be used to pass context information between the
351
+ * \ref CborParserOperations methods.
352
+ *
353
+ * \param dst The buffer the read bytes will be copied to.
354
+ *
355
+ * \param offset The starting position for the read relative to the
356
+ * current read position.
357
+ *
358
+ * \param len The number of bytes sought.
359
+ */
323
360
void * (* read_bytes )(void * token , void * dst , size_t offset , size_t len );
361
+
362
+ /**
363
+ * Skips past \a len bytes from the reader without reading them. The read
364
+ * pointer is advanced in the process.
365
+ *
366
+ * \param token An opaque object passed to \ref cbor_parser_init_reader
367
+ * that may be used to pass context information between the
368
+ * \ref CborParserOperations methods.
369
+ *
370
+ * \param len The number of bytes skipped.
371
+ */
324
372
void (* advance_bytes )(void * token , size_t len );
373
+
374
+ /**
375
+ * Overwrite the user-supplied pointer \a userptr with the address where the
376
+ * data indicated by \a offset is located, then advance the read pointer
377
+ * \a len bytes beyond that point.
378
+ *
379
+ * This routine is used for accessing strings embedded in CBOR documents
380
+ * (both text and binary strings).
381
+ *
382
+ * \param token An opaque object passed to \ref cbor_parser_init_reader
383
+ * that may be used to pass context information between the
384
+ * \ref CborParserOperations methods.
385
+ *
386
+ * \param userptr The pointer that will be updated to reference the location
387
+ * of the data in the buffer.
388
+ *
389
+ * \param offset The starting position for the read relative to the
390
+ * current read position.
391
+ *
392
+ * \param len The number of bytes sought.
393
+ */
325
394
CborError (* transfer_string )(void * token , const void * * userptr , size_t offset , size_t len );
326
395
};
327
396
0 commit comments