Architecture for to-string conversion
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- c
- Ambito
- backend-api-design
Direzione di ricerca
Inizia dal percorso attuale json_object-to-string e dalla relativa implementazione di struct printbuf, quindi esamina i punti di ingresso proposti fjson_object_write e fjson_object_write_ex. Il lavoro è completato quando le callback dell’utente possono ricevere l’output serializzato, il comportamento esistente di printbuf può essere costruito sull’API delle callback e le conversioni concorrenti non dipendono più da un buffer di output di proprietà dell’oggetto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?
- Lingua principale
- C
- Stelle
- 61
- Fork
- 34
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rsyslog/libfastjson
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
rsyslog/libfastjson#154 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
rsyslog/libfastjson#169 · 3 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
rsyslog/libfastjson#168 · 3 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
rsyslog/libfastjson#165 · 2 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
rsyslog/libfastjson#164 · 3 commenti ·
Tutte le issue di rsyslog/libfastjson
Issue simili
-
documentation
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
-
BUG: `tandg` and `cotdg` lose precision near their poles, `fresnel` is NaN for `|x| >= 2^512`Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
0.kind: build failure
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 2 giorni