Architecture for to-string conversion

オープン
#119 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
c

調査の方向性

現在の json_object-to-string パスとその struct printbuf 実装から始め、提案されているエントリーポイント fjson_object_write と fjson_object_write_ex を確認します。完了条件は、ユーザーコールバックがシリアライズされた出力を受け取れること、既存の printbuf の動作をコールバック API 上に構築できること、そして並行変換がオブジェクト所有の出力バッファに依存しなくなることです。

索引モデルが issue の本文から書いたものです。

説明

Hi Rainer,

We have some issues with converting the json tree to a string from multiple threads at the same time. I think the problem is with the printbuf member that is being used by two threads. We will probably be able to work around this, but after looking at the code, I think it is a peculiar design that the output buffer is part of the json_object.

What would you think of adding the following functions to libfastjson:

/**
 * Signature of a custom print function that can be implemented by the user.
 * @param ptr user-supplied pointer
 * @param buffer buffer to be written
 * @param size size of the buffer
 * @return size_t number of bytes written
 */
typedef size_t (fjson_print_fn)(void *ptr, const char *buffer, size_t size);

/**
 * Write the json tree to a user-supplied function
 * @param jso the fjson_object instance
 * @param func the user supplied function to which all data will be passed
 * @param ptr user-supplied pointer that is passed as first param to the callback
 * @returns the number of bytes written
 */
extern size_t fjson_object_write(struct fjson_object *jso, fjson_print_fn *func, void *ptr);

/**
 * Extended write function that allows extra flags to be passed
 * @param jso the fjson_object instance
 * @param flags formatting options, see FJSON_TO_STRING_PRETTY and other constants
 * @param func the user supplied function to which all data will be passed
 * @param ptr user-supplied pointer that is passed as first param to the callback
 * @returns the number of bytes written
 */
extern size_t fjson_object_write_ex(struct fjson_object *jso, int flags, fjson_print_fn *func, void *ptr);

This would allow users to supply their own output function, for example to write the json to a FILE*, or to write it to a fixed size buffer on the stack or to a dynamically growing buffer just like the current "struct printbuf" does. In fact, the "printbuf" implementation could be implemented on top of these functions.

This will often also be a performance improvement because now we're always stuck with the dynamically growing printbuf -- even if we have a pretty good idea how big the output is going to be, or when we want to write to a file instead of to a dynamically allocated buffer.

Are you willing to accept a pull request that implements this?

主要言語
C
スター
61
フォーク
34
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rsyslog/libfastjson のほかの issue

rsyslog/libfastjson の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。