Fix a bug Jed reported. More JSON work. Redo format layouts.

This commit is contained in:
JoelKatz
2012-10-01 20:09:24 -07:00
parent e7c9ee09f6
commit e2c257f50b
12 changed files with 335 additions and 264 deletions

View File

@@ -116,33 +116,32 @@ std::auto_ptr<SerializedType> STObject::makeDeserializedObject(SerializedTypeID
}
}
void STObject::set(SOElement::ptr elem)
void STObject::set(const std::vector<SOElement::ptr>& type)
{
mData.empty();
mType.empty();
while (elem->flags != SOE_END)
BOOST_FOREACH(const SOElement::ptr& elem, type)
{
mType.push_back(elem);
if (elem->flags == SOE_OPTIONAL)
giveObject(makeNonPresentObject(elem->e_field));
else
giveObject(makeDefaultObject(elem->e_field));
++elem;
}
}
bool STObject::setType(SOElement::ptrList t)
bool STObject::setType(const std::vector<SOElement::ptr> &type)
{
boost::ptr_vector<SerializedType> newData;
bool valid = true;
mType.empty();
while (t->flags != SOE_END)
BOOST_FOREACH(const SOElement::ptr& elem, type)
{
bool match = false;
for (boost::ptr_vector<SerializedType>::iterator it = mData.begin(); it != mData.end(); ++it)
if (it->getFName() == t->e_field)
if (it->getFName() == elem->e_field)
{
match = true;
newData.push_back(mData.release(it).release());
@@ -151,15 +150,15 @@ bool STObject::setType(SOElement::ptrList t)
if (!match)
{
if (t->flags != SOE_OPTIONAL)
if (elem->flags != SOE_OPTIONAL)
{
Log(lsTRACE) << "setType !valid missing";
valid = false;
}
newData.push_back(makeNonPresentObject(t->e_field));
newData.push_back(makeNonPresentObject(elem->e_field));
}
mType.push_back(t++);
mType.push_back(elem);
}
if (mData.size() != 0)
{
@@ -742,7 +741,7 @@ Json::Value STObject::getJson(int options) const
if (it.getSType() != STI_NOTPRESENT)
{
if (!it.getFName().hasName())
ret[boost::lexical_cast<std::string>(index)] = it.getJson(options);
ret[lexical_cast_i(index)] = it.getJson(options);
else
ret[it.getName()] = it.getJson(options);
}
@@ -837,11 +836,19 @@ std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::r
{
case STI_UINT8:
if (value.isString())
data.push_back(new STUInt8(field, boost::lexical_cast<unsigned char>(value.asString())));
else if (value.isInt())
data.push_back(new STUInt8(field, boost::lexical_cast<unsigned char>(value.asInt())));
data.push_back(new STUInt8(field, lexical_cast_s<unsigned char>(value.asString())));
else if (value.isInt())
{
if (value.asInt() < 0 || value.asInt() > 255)
throw std::runtime_error("value out of rand");
data.push_back(new STUInt8(field, static_cast<unsigned char>(value.asInt())));
}
else if (value.isUInt())
data.push_back(new STUInt8(field, boost::lexical_cast<unsigned char>(value.asUInt())));
{
if (value.asUInt() > 255)
throw std::runtime_error("value out of rand");
data.push_back(new STUInt8(field, static_cast<unsigned char>(value.asUInt())));
}
else
throw std::runtime_error("Incorrect type");
break;
@@ -854,7 +861,7 @@ std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::r
{
if (field == sfTransactionType)
{
TransactionFormat* f = getTxnFormat(strValue);
TransactionFormat* f = TransactionFormat::getTxnFormat(strValue);
if (!f)
throw std::runtime_error("Unknown transaction type");
data.push_back(new STUInt16(field, static_cast<uint16>(f->t_type)));
@@ -863,7 +870,7 @@ std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::r
}
else if (field == sfLedgerEntryType)
{
LedgerEntryFormat* f = getLgrFormat(strValue);
LedgerEntryFormat* f = LedgerEntryFormat::getLgrFormat(strValue);
if (!f)
throw std::runtime_error("Unknown ledger entry type");
data.push_back(new STUInt16(field, static_cast<uint16>(f->t_type)));
@@ -874,34 +881,34 @@ std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::r
throw std::runtime_error("Invalid field data");
}
else
data.push_back(new STUInt16(field, boost::lexical_cast<uint16>(strValue)));
data.push_back(new STUInt16(field, lexical_cast_s<uint16>(strValue)));
}
else if (value.isInt())
data.push_back(new STUInt16(field, boost::lexical_cast<uint16>(value.asInt())));
data.push_back(new STUInt16(field, static_cast<uint16>(value.asInt())));
else if (value.isUInt())
data.push_back(new STUInt16(field, boost::lexical_cast<uint16>(value.asUInt())));
data.push_back(new STUInt16(field, static_cast<uint16>(value.asUInt())));
else
throw std::runtime_error("Incorrect type");
break;
case STI_UINT32:
if (value.isString())
data.push_back(new STUInt32(field, boost::lexical_cast<uint32>(value.asString())));
data.push_back(new STUInt32(field, lexical_cast_s<uint32>(value.asString())));
else if (value.isInt())
data.push_back(new STUInt32(field, boost::lexical_cast<uint32>(value.asInt())));
data.push_back(new STUInt32(field, static_cast<uint32>(value.asInt())));
else if (value.isUInt())
data.push_back(new STUInt32(field, boost::lexical_cast<uint32>(value.asUInt())));
data.push_back(new STUInt32(field, static_cast<uint32>(value.asUInt())));
else
throw std::runtime_error("Incorrect type");
break;
case STI_UINT64:
if (value.isString())
data.push_back(new STUInt64(field, boost::lexical_cast<uint64>(value.asString())));
data.push_back(new STUInt64(field, lexical_cast_s<uint64>(value.asString())));
else if (value.isInt())
data.push_back(new STUInt64(field, boost::lexical_cast<uint64>(value.asInt())));
data.push_back(new STUInt64(field, static_cast<uint64>(value.asInt())));
else if (value.isUInt())
data.push_back(new STUInt64(field, boost::lexical_cast<uint64>(value.asUInt())));
data.push_back(new STUInt64(field, static_cast<uint64>(value.asUInt())));
else
throw std::runtime_error("Incorrect type");
break;
@@ -929,7 +936,10 @@ std::auto_ptr<STObject> STObject::parseJson(const Json::Value& object, SField::r
break;
case STI_VL:
{
// WRITEME
}
break;
case STI_AMOUNT:
// WRITEME