mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Tidy up and annotate
This commit is contained in:
@@ -23,6 +23,11 @@ enum SerializedTypeID
|
||||
STI_VALIDATION = 10003,
|
||||
};
|
||||
|
||||
/** Identifies fields.
|
||||
|
||||
Fields are necessary to tag data in signed transactions so that
|
||||
the binary format of the transaction can be canonicalized.
|
||||
*/
|
||||
// VFALCO TODO rename this to NamedField
|
||||
class SField
|
||||
{
|
||||
@@ -43,40 +48,58 @@ public:
|
||||
const int fieldCode; // (type<<16)|index
|
||||
const SerializedTypeID fieldType; // STI_*
|
||||
const int fieldValue; // Code number for protocol
|
||||
std::string fieldName;
|
||||
std::string fieldName;
|
||||
int fieldMeta;
|
||||
int fieldNum;
|
||||
bool signingField;
|
||||
|
||||
SField(int fc, SerializedTypeID tid, int fv, const char* fn) :
|
||||
fieldCode(fc), fieldType(tid), fieldValue(fv), fieldName(fn), fieldMeta(sMD_Default), signingField(true)
|
||||
SField (int fc, SerializedTypeID tid, int fv, const char* fn)
|
||||
: fieldCode (fc)
|
||||
, fieldType (tid)
|
||||
, fieldValue (fv)
|
||||
, fieldName (fn)
|
||||
, fieldMeta (sMD_Default)
|
||||
, signingField (true)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mapMutex);
|
||||
codeToField[fieldCode] = this;
|
||||
fieldNum = ++num;
|
||||
|
||||
codeToField[fieldCode] = this;
|
||||
|
||||
fieldNum = ++num;
|
||||
}
|
||||
|
||||
SField(SerializedTypeID tid, int fv, const char *fn) :
|
||||
fieldCode(FIELD_CODE(tid, fv)), fieldType(tid), fieldValue(fv), fieldName(fn),
|
||||
fieldMeta(sMD_Default), signingField(true)
|
||||
SField (SerializedTypeID tid, int fv, const char *fn)
|
||||
: fieldCode (FIELD_CODE (tid, fv))
|
||||
, fieldType (tid)
|
||||
, fieldValue (fv)
|
||||
, fieldName (fn)
|
||||
, fieldMeta (sMD_Default)
|
||||
, signingField (true)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mapMutex);
|
||||
codeToField[fieldCode] = this;
|
||||
fieldNum = ++num;
|
||||
|
||||
codeToField[fieldCode] = this;
|
||||
|
||||
fieldNum = ++num;
|
||||
}
|
||||
|
||||
SField(int fc) : fieldCode(fc), fieldType(STI_UNKNOWN), fieldValue(0), fieldMeta(sMD_Never), signingField(true)
|
||||
explicit SField (int fc)
|
||||
: fieldCode (fc)
|
||||
, fieldType (STI_UNKNOWN)
|
||||
, fieldValue (0)
|
||||
, fieldMeta (sMD_Never)
|
||||
, signingField (true)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mapMutex);
|
||||
fieldNum = ++num;
|
||||
}
|
||||
|
||||
~SField();
|
||||
~SField ();
|
||||
|
||||
static SField::ref getField(int fieldCode);
|
||||
static SField::ref getField(const std::string& fieldName);
|
||||
static SField::ref getField(int type, int value) { return getField(FIELD_CODE(type, value)); }
|
||||
static SField::ref getField(SerializedTypeID type, int value) { return getField(FIELD_CODE(type, value)); }
|
||||
static SField::ref getField (int fieldCode);
|
||||
static SField::ref getField (const std::string& fieldName);
|
||||
static SField::ref getField (int type, int value) { return getField(FIELD_CODE(type, value)); }
|
||||
static SField::ref getField (SerializedTypeID type, int value) { return getField(FIELD_CODE(type, value)); }
|
||||
|
||||
std::string getName() const;
|
||||
bool hasName() const { return !fieldName.empty(); }
|
||||
@@ -86,8 +109,11 @@ public:
|
||||
bool isUseful() const { return fieldCode > 0; }
|
||||
bool isKnown() const { return fieldType != STI_UNKNOWN; }
|
||||
bool isBinary() const { return fieldValue < 256; }
|
||||
bool isDiscardable() const { return fieldValue > 256; }
|
||||
int getCode() const { return fieldCode; }
|
||||
|
||||
// VFALCO NOTE What is a discardable field?
|
||||
bool isDiscardable() const { return fieldValue > 256; }
|
||||
|
||||
int getCode() const { return fieldCode; }
|
||||
int getNum() const { return fieldNum; }
|
||||
static int getNumFields() { return num; }
|
||||
|
||||
@@ -99,8 +125,9 @@ public:
|
||||
bool shouldInclude(bool withSigningField) const
|
||||
{ return (fieldValue < 256) && (withSigningField || signingField); }
|
||||
|
||||
bool operator==(const SField& f) const { return fieldCode == f.fieldCode; }
|
||||
bool operator!=(const SField& f) const { return fieldCode != f.fieldCode; }
|
||||
bool operator== (const SField& f) const { return fieldCode == f.fieldCode; }
|
||||
|
||||
bool operator!= (const SField& f) const { return fieldCode != f.fieldCode; }
|
||||
|
||||
static int compare(SField::ref f1, SField::ref f2);
|
||||
|
||||
@@ -110,7 +137,7 @@ protected:
|
||||
static boost::mutex mapMutex;
|
||||
static int num;
|
||||
|
||||
SField(SerializedTypeID id, int val);
|
||||
SField (SerializedTypeID id, int val);
|
||||
};
|
||||
|
||||
extern SField sfInvalid, sfGeneric, sfLedgerEntry, sfTransaction, sfValidation;
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
// This is not really a header file, but it can be used as one with
|
||||
// appropriate #define statements.
|
||||
|
||||
/*
|
||||
Common type common field - 1 byte
|
||||
Common type uncommon field - 2 bytes
|
||||
...
|
||||
|
||||
Rarity of fields determines the number of bytes.
|
||||
This is done to reduce the average size of the messages.
|
||||
*/
|
||||
|
||||
// types (common)
|
||||
TYPE(Int16, UINT16, 1)
|
||||
TYPE(Int32, UINT32, 2)
|
||||
|
||||
@@ -62,6 +62,7 @@ UPTR_T<SerializedType> STObject::makeDefaultObject(SerializedTypeID id, SField::
|
||||
}
|
||||
}
|
||||
|
||||
// VFALCO TODO Remove the 'depth' parameter
|
||||
UPTR_T<SerializedType> STObject::makeDeserializedObject(SerializedTypeID id, SField::ref name,
|
||||
SerializerIterator& sit, int depth)
|
||||
{
|
||||
@@ -184,7 +185,8 @@ bool STObject::setType(const SOTemplate &type)
|
||||
bool STObject::isValidForType()
|
||||
{
|
||||
boost::ptr_vector<SerializedType>::iterator it = mData.begin();
|
||||
BOOST_FOREACH(const SOElement* elem, mType->peek())
|
||||
|
||||
BOOST_FOREACH(const SOElement* elem, mType->peek())
|
||||
{
|
||||
if (it == mData.end())
|
||||
return false;
|
||||
@@ -227,7 +229,7 @@ bool STObject::set(SerializerIterator& sit, int depth)
|
||||
*/
|
||||
|
||||
// return true = terminated with end-of-object
|
||||
bool STObject::set(SerializerIterator& sit, int depth)
|
||||
bool STObject::set (SerializerIterator& sit, int depth)
|
||||
{
|
||||
bool reachedEndOfObject = false;
|
||||
|
||||
|
||||
@@ -38,8 +38,13 @@ public:
|
||||
virtual bool isDefault() const { return mData.empty(); }
|
||||
|
||||
virtual void add(Serializer& s) const { add(s, true); } // just inner elements
|
||||
void add(Serializer& s, bool withSignature) const;
|
||||
|
||||
void add(Serializer& s, bool withSignature) const;
|
||||
|
||||
// VFALCO NOTE does this return an expensive copy of an object with a dynamic buffer?
|
||||
// VFALCO TODO Remove this function and fix the few callers.
|
||||
Serializer getSerializer() const { Serializer s; add(s); return s; }
|
||||
|
||||
std::string getFullText() const;
|
||||
std::string getText() const;
|
||||
virtual Json::Value getJson(int options) const;
|
||||
@@ -116,14 +121,24 @@ public:
|
||||
bool delField(SField::ref field);
|
||||
void delField(int index);
|
||||
|
||||
static UPTR_T<SerializedType> makeDefaultObject(SerializedTypeID id, SField::ref name);
|
||||
static UPTR_T<SerializedType> makeDeserializedObject(SerializedTypeID id, SField::ref name,
|
||||
SerializerIterator&, int depth);
|
||||
static UPTR_T <SerializedType> makeDefaultObject(SerializedTypeID id, SField::ref name);
|
||||
|
||||
static UPTR_T<SerializedType> makeNonPresentObject(SField::ref name)
|
||||
{ return makeDefaultObject(STI_NOTPRESENT, name); }
|
||||
static UPTR_T<SerializedType> makeDefaultObject(SField::ref name)
|
||||
{ return makeDefaultObject(name.fieldType, name); }
|
||||
// VFALCO TODO remove the 'depth' parameter
|
||||
static UPTR_T<SerializedType> makeDeserializedObject (
|
||||
SerializedTypeID id,
|
||||
SField::ref name,
|
||||
SerializerIterator &,
|
||||
int depth);
|
||||
|
||||
static UPTR_T<SerializedType> makeNonPresentObject (SField::ref name)
|
||||
{
|
||||
return makeDefaultObject(STI_NOTPRESENT, name);
|
||||
}
|
||||
|
||||
static UPTR_T<SerializedType> makeDefaultObject (SField::ref name)
|
||||
{
|
||||
return makeDefaultObject(name.fieldType, name);
|
||||
}
|
||||
|
||||
// field iterator stuff
|
||||
typedef boost::ptr_vector<SerializedType>::iterator iterator;
|
||||
@@ -148,9 +163,7 @@ private:
|
||||
{ mData.swap(data); }
|
||||
};
|
||||
|
||||
// allow ptr_* collections of STObject's
|
||||
inline STObject* new_clone(const STObject& s) { return s.oClone().release(); }
|
||||
inline void delete_clone(const STObject* s) { boost::checked_delete(s); }
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
inline STObject::iterator range_begin(STObject& x) { return x.begin(); }
|
||||
inline STObject::iterator range_end(STObject &x) { return x.end(); }
|
||||
|
||||
@@ -50,6 +50,9 @@ public:
|
||||
*/
|
||||
SOTemplate ();
|
||||
|
||||
// VFALCO NOTE Why do we even bother with the 'private' keyword if
|
||||
// this function is present?
|
||||
//
|
||||
std::vector <SOElement const*> const& peek() const
|
||||
{
|
||||
return mTypes;
|
||||
@@ -64,8 +67,9 @@ public:
|
||||
int getIndex (SField::ref) const;
|
||||
|
||||
private:
|
||||
std::vector<SOElement const*> mTypes;
|
||||
std::vector <int> mIndex; // field num -> index
|
||||
std::vector <SOElement const*> mTypes;
|
||||
|
||||
std::vector <int> mIndex; // field num -> index
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user