From df35adc43856cfef48abd3af93cf4275e7866899 Mon Sep 17 00:00:00 2001 From: Sean Middleditch Date: Sat, 16 Jan 2010 20:21:52 -0800 Subject: [PATCH] add comments noting inefficiency of stream ops --- janssonxx.h | 4 ++-- janssonxx.tcc | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/janssonxx.h b/janssonxx.h index 15f34f7..260450f 100644 --- a/janssonxx.h +++ b/janssonxx.h @@ -293,10 +293,10 @@ namespace jansson { } // namespace jansson -// stream JSON value out +// stream JSON value out -- inefficient and not recommended for production use inline std::ostream& operator<<(std::ostream& os, const jansson::Value& value); -// read JSON value +// read JSON value -- inefficient and not recommended for production use inline std::istream& operator>>(std::istream& is, jansson::Value& value); // include implementation code diff --git a/janssonxx.tcc b/janssonxx.tcc index cdbadd8..74e4be5 100644 --- a/janssonxx.tcc +++ b/janssonxx.tcc @@ -438,8 +438,10 @@ namespace jansson { // stream JSON value out std::ostream& operator<<(std::ostream& os, const jansson::Value& value) { + // get the temporary serialize string char* tmp = value.save_string(); if (tmp != 0) { + // stream temp string out and release it os << tmp; free(tmp); } @@ -448,9 +450,11 @@ std::ostream& operator<<(std::ostream& os, const jansson::Value& value) { // read JSON value std::istream& operator>>(std::istream& is, jansson::Value& value) { + // buffer the remaining bytes into a single string for Jansson std::stringstream tmp; while (is) tmp << static_cast(is.get()); + // parse the buffered string value = jansson::Value::load_string(tmp.str().c_str()); return is; } -- 2.7.4