Exemplo n.º 1
0
ssize_t objectSize(const pbnjson::JValue& value)
{
	ssize_t result = 0;
	for (pbnjson::JValue::ObjectConstIterator i = value.begin(); i != value.end(); i++)
		result++;
	return result;
}
Exemplo n.º 2
0
    static void
    convert(const pbnjson::JValue &j, hl::optional<Type>& v)
    {
        if(j.isNull())
        {
            v.set_is_set(false);
            return;
        }
        v.set_is_set(true);

        //
        // Delegate the conversion to the basic
        // conversion type
        conversion<Type>::convert(j, v.get());
    }
Exemplo n.º 3
0
 static void convert(const pbnjson::JValue &j, int &v)
 {
     LG_ASSERT(j.isNumber());
     v = j.asNumber<int>();
 }
Exemplo n.º 4
0
 static void convert(const pbnjson::JValue &j, double &v)
 {
     LG_ASSERT(j.isNumber());
     v = j.asNumber<double>();
 }
Exemplo n.º 5
0
 static void convert(const pbnjson::JValue &j, std::string &v)
 {
     LG_ASSERT(j.isString());
     v = j.asString();
 }
Exemplo n.º 6
0
 static void convert(const pbnjson::JValue &j, bool &v)
 {
     LG_ASSERT(j.isBoolean());
     v = j.asBool();
 }
Exemplo n.º 7
0
static void statistics(pbnjson::JValue json, JSONStats &stats)
{
	if (json.isObject()) {
		stats.numObjects++;
		pbnjson::JValue::ObjectIterator i;
		for (i = json.begin(); i != json.end(); i++) {
			stats.numKeys ++;
			stats.keySize += (*i).first.asString().length();
			pbnjson::JValue child = (*i).second;
			statistics(child, stats);
		}
	} else if (json.isArray()) {
		stats.numArrays++;
		stats.numElements += json.arraySize();
		for (ssize_t i = 0; i < json.arraySize(); i++) {
			statistics(json, stats);
		}
	} else if (json.isString()) {
		stats.numStrings++;
		stats.stringSize += json.asString().length();
	} else if (json.isNumber()) {
		stats.numNumbers++;
	} else if (json.isBoolean()) {
		stats.numBooleans++;
	} else if (json.isNull()) {
		stats.numNulls++;
	}
}