mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Get ready for Json decode.
This commit is contained in:
@@ -75,7 +75,7 @@ SField::ref SField::getField(int type, int value)
|
||||
|
||||
std::string SField::getName() const
|
||||
{
|
||||
if (fieldName != NULL)
|
||||
if (!fieldName.empty())
|
||||
return fieldName;
|
||||
if (fieldValue == 0)
|
||||
return "";
|
||||
|
||||
@@ -48,20 +48,20 @@ public:
|
||||
const int fieldCode; // (type<<16)|index
|
||||
const SerializedTypeID fieldType; // STI_*
|
||||
const int fieldValue; // Code number for protocol
|
||||
const char* fieldName;
|
||||
std::string fieldName;
|
||||
|
||||
SField(int fc, SerializedTypeID tid, int fv, const char* fn) :
|
||||
fieldCode(fc), fieldType(tid), fieldValue(fv), fieldName(fn)
|
||||
{ codeToField[fc] = this; }
|
||||
|
||||
SField(int fc) : fieldCode(fc), fieldType(STI_UNKNOWN), fieldValue(0), fieldName(NULL) { ; }
|
||||
SField(int fc) : fieldCode(fc), fieldType(STI_UNKNOWN), fieldValue(0) { ; }
|
||||
|
||||
static SField::ref getField(int fieldCode);
|
||||
static SField::ref getField(int fieldType, int fieldValue);
|
||||
static SField::ref getField(SerializedTypeID type, int value) { return getField(FIELD_CODE(type, value)); }
|
||||
|
||||
std::string getName() const;
|
||||
bool hasName() const { return (fieldName != NULL) || (fieldValue != 0); }
|
||||
bool hasName() const { return !fieldName.empty(); }
|
||||
|
||||
bool isGeneric() const { return fieldCode == 0; }
|
||||
bool isInvalid() const { return fieldCode == -1; }
|
||||
|
||||
@@ -703,7 +703,7 @@ Json::Value STObject::getJson(int options) const
|
||||
{
|
||||
if (it.getSType() != STI_NOTPRESENT)
|
||||
{
|
||||
if (it.getName() == NULL)
|
||||
if (!it.getFName().hasName())
|
||||
ret[boost::lexical_cast<std::string>(index)] = it.getJson(options);
|
||||
else
|
||||
ret[it.getName()] = it.getJson(options);
|
||||
@@ -777,6 +777,19 @@ STArray* STArray::construct(SerializerIterator& sit, SField::ref field)
|
||||
return new STArray(field, value);
|
||||
}
|
||||
|
||||
STObject::STObject(const Json::Value& object, SField::ref name) : SerializedType(name)
|
||||
{
|
||||
if (!object.isObject())
|
||||
throw std::runtime_error("Value is not an object");
|
||||
|
||||
Json::Value::Members members(object.getMemberNames());
|
||||
for (Json::Value::Members::iterator it = members.begin(), end = members.end(); it != end; ++it)
|
||||
{
|
||||
const std::string& name = *it;
|
||||
const Json::Value& value = object[name];
|
||||
// WRITEME
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ public:
|
||||
STObject(SOElement::ptrList type, SerializerIterator& sit, SField::ref name) : SerializedType(name)
|
||||
{ set(sit); setType(type); }
|
||||
|
||||
STObject(const Json::Value& value, SField::ref name);
|
||||
|
||||
virtual ~STObject() { ; }
|
||||
|
||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, SField::ref name);
|
||||
|
||||
@@ -19,7 +19,7 @@ std::string SerializedType::getFullText() const
|
||||
std::string ret;
|
||||
if (getSType() != STI_NOTPRESENT)
|
||||
{
|
||||
if(fName != NULL)
|
||||
if(fName->hasName())
|
||||
{
|
||||
ret = fName->fieldName;
|
||||
ret += " = ";
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
|
||||
void setFName(SField::ref n) { fName = &n; assert(fName); }
|
||||
SField::ref getFName() const { return *fName; }
|
||||
const char *getName() const { return fName->fieldName; }
|
||||
std::string getName() const { return fName->fieldName; }
|
||||
|
||||
virtual SerializedTypeID getSType() const { return STI_NOTPRESENT; }
|
||||
std::auto_ptr<SerializedType> clone() const { return std::auto_ptr<SerializedType>(duplicate()); }
|
||||
|
||||
Reference in New Issue
Block a user