From 6a204b1bddc711b768d598c6ac0a16413f48d3c3 Mon Sep 17 00:00:00 2001 From: Rider Linden <rider@lindenlab.com> Date: Thu, 10 Sep 2015 16:48:01 -0700 Subject: MAINT-5575: Finished converting experience cache to singleton MAINT-4952: Coverted VMM to coroutines --- indra/llcommon/llsdjson.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++ indra/llcommon/llsdjson.h | 18 +++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llsdjson.cpp b/indra/llcommon/llsdjson.cpp index 2afdba388a..8caaaee534 100644 --- a/indra/llcommon/llsdjson.cpp +++ b/indra/llcommon/llsdjson.cpp @@ -76,3 +76,51 @@ LLSD LlsdFromJson(const Json::Value &val) } return result; } + +//========================================================================= +Json::Value LlsdToJson(const LLSD &val) +{ + Json::Value result; + + switch (val.type()) + { + case LLSD::TypeUndefined: + result = Json::Value::null; + break; + case LLSD::TypeBoolean: + result = Json::Value(static_cast<bool>(val.asBoolean())); + break; + case LLSD::TypeInteger: + result = Json::Value(static_cast<int>(val.asInteger())); + break; + case LLSD::TypeReal: + result = Json::Value(static_cast<double>(val.asReal())); + break; + case LLSD::TypeURI: + case LLSD::TypeDate: + case LLSD::TypeUUID: + case LLSD::TypeString: + result = Json::Value(val.asString()); + break; + case LLSD::TypeMap: + result = Json::Value(Json::objectValue); + for (LLSD::map_const_iterator it = val.beginMap(); it != val.endMap(); ++it) + { + result[it->first] = LlsdToJson(it->second); + } + break; + case LLSD::TypeArray: + result = Json::Value(Json::arrayValue); + for (LLSD::array_const_iterator it = val.beginArray(); it != val.endArray(); ++it) + { + result.append(LlsdToJson(*it)); + } + break; + case LLSD::TypeBinary: + default: + LL_ERRS("LlsdToJson") << "Unsupported conversion to JSON from LLSD type (" << val.type() << ")." << LL_ENDL; + break; + } + + return result; +} diff --git a/indra/llcommon/llsdjson.h b/indra/llcommon/llsdjson.h index cdf9fed500..2be7112404 100644 --- a/indra/llcommon/llsdjson.h +++ b/indra/llcommon/llsdjson.h @@ -55,5 +55,23 @@ /// Order is preserved for an array but not for objects. LLSD LlsdFromJson(const Json::Value &val); +/// Convert an LLSD object into Parsed JSON object maintaining member names and +/// array indexs. +/// +/// Types are converted as follows: +/// LLSD Type | JSON Type +/// --------------+---------------- +/// TypeUndefined | null +/// TypeBoolean | boolean +/// TypeInteger | integer +/// TypeReal | real/numeric +/// TypeString | string +/// TypeURI | string +/// TypeDate | string +/// TypeUUID | string +/// TypeMap | object +/// TypeArray | array +/// TypeBinary | unsupported +Json::Value LlsdToJson(const LLSD &val); #endif // LL_LLSDJSON_H -- cgit v1.2.3