Skip to content

Commit 69d79ab

Browse files
committed
cbor: Document the reader interface.
1 parent db6ee7a commit 69d79ab

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

src/cbor.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,80 @@ enum CborParserIteratorFlags
320320
};
321321

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

0 commit comments

Comments
 (0)