This function exports a single object to an output stream in JSON format.
MCO_RET classname_json_get( /*IN*/ classname *handle, void *stream_handle, mco_stream_write output_stream_writer );
handle | The address of a variable of type |
stream_handle |
The output stream handle |
output_stream_writer | The handler function called by the runtime to format output |
This function exports a single object to an output stream. The runtime calls the application-defined handler to manage the output stream.
Note that this function is only generated if the
-json
flag is passed to themcocomp
utility.It is the application’s responsibility to open the output stream, in the proper mode to stream binary data, and to ensure that there is adequate space at the destination to hold the object. (See the control structure mco_stream_write for further details.)
MCO_S_OK | Database data exported successfully |
MCO_E_WRITE_STREAM | Error writing to output stream |
/* Stream writer function matching the mco_stream_write prototype */ mco_size_sig_t file_writer(void *stream_handle /* FILE * */, const void *from, mco_size_t nbytes) { return fwrite(from, 1, nbytes, (FILE *)stream_handle); } /* Function to export a single object */ void export_obj() { mco_trans_h t; mco_cursor_t cur; <classname> obj; FILE *f = fopen("obj.json", "wb"); /* Use the cursor to locate an object */ mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t); <classname>_<indexname>_index_cursor(t, &cur); mco_cursor_first(t, &cur); <classname>_from_cursor(t, &cur, &obj); /* Export the object */ <classname>_json_get(&obj, f, file_writer); mco_cursor_close(t, &cur); mco_trans_rollback(t); fclose(f); }