added the ctx parameter to the json write callback
This commit is contained in:
		| @ -90,7 +90,7 @@ static int on_json_inst (mio_json_t* json, mio_json_inst_t inst,	mio_oow_t level | |||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int write_json_element (mio_jsonwr_t* jsonwr, const mio_bch_t* dptr, mio_oow_t dlen) | static int write_json_element (mio_jsonwr_t* jsonwr, const mio_bch_t* dptr, mio_oow_t dlen, void* ctx) | ||||||
| { | { | ||||||
| 	write (1, dptr, dlen); | 	write (1, dptr, dlen); | ||||||
| 	return 0; | 	return 0; | ||||||
| @ -146,7 +146,7 @@ int main (int argc, char* argv[]) | |||||||
| 	 | 	 | ||||||
| 		jsonwr = mio_jsonwr_open (mio, 0); | 		jsonwr = mio_jsonwr_open (mio, 0); | ||||||
|  |  | ||||||
| 		mio_jsonwr_setwritecb (jsonwr, write_json_element); | 		mio_jsonwr_setwritecb (jsonwr, write_json_element, MIO_NULL); | ||||||
|  |  | ||||||
| 		mio_jsonwr_startarray (jsonwr); | 		mio_jsonwr_startarray (jsonwr); | ||||||
| 		 | 		 | ||||||
|  | |||||||
| @ -815,7 +815,7 @@ void mio_jsonwr_close (mio_jsonwr_t* jsonwr) | |||||||
| 	mio_freemem (jsonwr->mio, jsonwr); | 	mio_freemem (jsonwr->mio, jsonwr); | ||||||
| } | } | ||||||
|  |  | ||||||
| static int write_nothing (mio_jsonwr_t* jsonwr, const mio_bch_t* dptr, mio_oow_t dlen) | static int write_nothing (mio_jsonwr_t* jsonwr, const mio_bch_t* dptr, mio_oow_t dlen, void* ctx) | ||||||
| { | { | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
| @ -837,7 +837,7 @@ static int flush_wbuf (mio_jsonwr_t* jsonwr) | |||||||
| { | { | ||||||
| 	int ret = 0; | 	int ret = 0; | ||||||
|  |  | ||||||
| 	if (jsonwr->writecb(jsonwr, jsonwr->wbuf, jsonwr->wbuf_len) <= -1) ret = -1; | 	if (jsonwr->writecb(jsonwr, jsonwr->wbuf, jsonwr->wbuf_len, jsonwr->wctx) <= -1) ret = -1; | ||||||
| 	jsonwr->wbuf_len = 0; /* reset the buffer length regardless of writing result */ | 	jsonwr->wbuf_len = 0; /* reset the buffer length regardless of writing result */ | ||||||
|  |  | ||||||
| 	return ret; | 	return ret; | ||||||
| @ -851,9 +851,10 @@ void mio_jsonwr_fini (mio_jsonwr_t* jsonwr) | |||||||
|  |  | ||||||
| /* ========================================================================= */ | /* ========================================================================= */ | ||||||
|  |  | ||||||
| void mio_jsonwr_setwritecb (mio_jsonwr_t* jsonwr, mio_jsonwr_writecb_t writecb) | void mio_jsonwr_setwritecb (mio_jsonwr_t* jsonwr, mio_jsonwr_writecb_t writecb, void* ctx) | ||||||
| { | { | ||||||
| 	jsonwr->writecb = writecb; | 	jsonwr->writecb = writecb; | ||||||
|  | 	jsonwr->wctx = ctx; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int escape_char (mio_uch_t uch, mio_uch_t* xch) | static int escape_char (mio_uch_t uch, mio_uch_t* xch) | ||||||
|  | |||||||
| @ -133,9 +133,9 @@ typedef struct mio_jsonwr_t mio_jsonwr_t; | |||||||
|  |  | ||||||
| typedef int (*mio_jsonwr_writecb_t) ( | typedef int (*mio_jsonwr_writecb_t) ( | ||||||
| 	mio_jsonwr_t*         jsonwr, | 	mio_jsonwr_t*         jsonwr, | ||||||
| 	/*mio_oow_t           level,*/ |  | ||||||
| 	const mio_bch_t*      dptr, | 	const mio_bch_t*      dptr, | ||||||
| 	mio_oow_t             dlen | 	mio_oow_t             dlen, | ||||||
|  | 	void*                 ctx | ||||||
| ); | ); | ||||||
|  |  | ||||||
| typedef struct mio_jsonwr_state_node_t mio_jsonwr_state_node_t; | typedef struct mio_jsonwr_state_node_t mio_jsonwr_state_node_t; | ||||||
| @ -156,6 +156,7 @@ struct mio_jsonwr_t | |||||||
| 	mio_jsonwr_state_node_t* state_stack; | 	mio_jsonwr_state_node_t* state_stack; | ||||||
| 	int pretty; | 	int pretty; | ||||||
|  |  | ||||||
|  | 	void* wctx;	 | ||||||
| 	mio_bch_t wbuf[8192]; | 	mio_bch_t wbuf[8192]; | ||||||
| 	mio_oow_t wbuf_len; | 	mio_oow_t wbuf_len; | ||||||
| }; | }; | ||||||
| @ -265,7 +266,8 @@ static MIO_INLINE void* mio_jsonwr_getxtn (mio_jsonwr_t* jsonwr) { return (void* | |||||||
|  |  | ||||||
| MIO_EXPORT void mio_jsonwr_setwritecb ( | MIO_EXPORT void mio_jsonwr_setwritecb ( | ||||||
| 	mio_jsonwr_t*        jsonwr, | 	mio_jsonwr_t*        jsonwr, | ||||||
| 	mio_jsonwr_writecb_t writecb | 	mio_jsonwr_writecb_t writecb, | ||||||
|  | 	void*                ctx | ||||||
| ); | ); | ||||||
|  |  | ||||||
| MIO_EXPORT int mio_jsonwr_write ( | MIO_EXPORT int mio_jsonwr_write ( | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user