Commit a708c3ab authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

buffer: allow JSON indention

parent 9ea08ef8
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
int parseJson(json_t **j); int parseJson(json_t **j);
int appendJson(json_t *j); int appendJson(json_t *j, int flags = JSON_INDENT(4));
}; };
} /* namespace villas */ } /* namespace villas */
...@@ -39,7 +39,7 @@ protected: ...@@ -39,7 +39,7 @@ protected:
public: public:
/** Encode JSON document /p j and append it to the buffer */ /** Encode JSON document /p j and append it to the buffer */
int encode(json_t *j); int encode(json_t *j, int flags = JSON_INDENT(4));
/** Decode JSON document from the beginning of the buffer */ /** Decode JSON document from the beginning of the buffer */
json_t * decode(); json_t * decode();
......
...@@ -75,11 +75,11 @@ int Buffer::parseJson(json_t **j) ...@@ -75,11 +75,11 @@ int Buffer::parseJson(json_t **j)
return 0; return 0;
} }
int Buffer::appendJson(json_t *j) int Buffer::appendJson(json_t *j, int flags)
{ {
size_t l; size_t l;
retry: l = json_dumpb(j, buf + len, size - len, 0); retry: l = json_dumpb(j, buf + len, size - len, flags);
if (size < len + l) { if (size < len + l) {
buf = (char *) realloc(buf, len + l); buf = (char *) realloc(buf, len + l);
if (!buf) if (!buf)
......
...@@ -40,9 +40,9 @@ json_t * JsonBuffer::decode() ...@@ -40,9 +40,9 @@ json_t * JsonBuffer::decode()
return j; return j;
} }
int JsonBuffer::encode(json_t *j) int JsonBuffer::encode(json_t *j, int flags)
{ {
return json_dump_callback(j, callback, this, 0); return json_dump_callback(j, callback, this, flags);
} }
int JsonBuffer::callback(const char *data, size_t len, void *ctx) int JsonBuffer::callback(const char *data, size_t len, void *ctx)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment