コード例 #1
0
ファイル: bson-reader.c プロジェクト: joaquimserafim/libbson
/**
 * bson_reader_read:
 * @reader: A bson_reader_t.
 * @reached_eof: A location for a bson_bool_t.
 *
 * Reads the next bson_t in the underlying memory or storage.  The resulting
 * bson_t should not be modified or freed. You may copy it and iterate over it.
 * Functions that take a const bson_t* are safe to use.
 *
 * This structure does not survive calls to bson_reader_read() or
 * bson_reader_destroy() as it uses memory allocated by the reader or
 * underlying storage/memory.
 *
 * If NULL is returned then @reached_eof will be set to TRUE if the end of the
 * file or buffer was reached. This indicates if there was an error parsing the
 * document stream.
 *
 * Returns: A const bson_t that should not be modified or freed.
 */
const bson_t *
bson_reader_read (bson_reader_t *reader,
                  bson_bool_t   *reached_eof)
{
   bson_return_val_if_fail (reader, NULL);

   switch (reader->type) {
   case BSON_READER_FD:
      return _bson_reader_fd_read ((bson_reader_fd_t *)reader, reached_eof);

   case BSON_READER_DATA:
      return _bson_reader_data_read ((bson_reader_data_t *)reader, reached_eof);

   default:
      fprintf (stderr, "No such reader type: %02x\n", reader->type);
      break;
   }

   return NULL;
}
コード例 #2
0
ファイル: bson-reader.c プロジェクト: guruofquality/libbson
const bson_t *
bson_reader_read (bson_reader_t *reader,      /* IN */
                  bool          *reached_eof) /* OUT */
{
   bson_return_val_if_fail (reader, NULL);

   switch (reader->type) {
   case BSON_READER_HANDLE:
      return _bson_reader_handle_read ((bson_reader_handle_t *)reader, reached_eof);

   case BSON_READER_DATA:
      return _bson_reader_data_read ((bson_reader_data_t *)reader, reached_eof);

   default:
      fprintf (stderr, "No such reader type: %02x\n", reader->type);
      break;
   }

   return NULL;
}