20 #include <ripple/protocol/STObject.h>
21 #include <ripple/protocol/InnerObjectFormats.h>
22 #include <ripple/protocol/STAccount.h>
23 #include <ripple/protocol/STArray.h>
24 #include <ripple/protocol/STBlob.h>
25 #include <ripple/basics/Log.h>
40 , v_(
std::move(other.v_))
64 v_.reserve(type.
size());
75 Throw<std::runtime_error> (
"Maximum nesting depth of STObject exceeded");
84 v_ = std::move(other.v_);
94 for (
auto const& elem : type)
105 auto throwFieldErr = [] (
std::string const& field,
char const* description)
108 ss <<
"Field '" << field <<
"' " << description;
110 JLOG (
debugLog().error()) <<
"STObject::applyTemplate failed: " << text;
111 Throw<FieldErr> (text);
117 for (
auto const& e : type)
121 { return b.get().getFName() == e.sField(); });
122 if (iter != v_.end())
124 if ((e.style() ==
soeDEFAULT) && iter->get().isDefault())
126 throwFieldErr (e.sField().fieldName,
127 "may not be explicitly set to default.");
129 v.emplace_back(std::move(*iter));
136 throwFieldErr (e.sField().fieldName,
137 "is required but missing.");
142 for (
auto const& e : v_)
145 if (! e->getFName().isDiscardable())
147 throwFieldErr (e->getFName().getName(),
148 "found in disallowed location.");
161 applyTemplate (*elements);
167 bool reachedEndOfObject =
false;
172 while (!sit.empty ())
178 sit.getFieldID(type, field);
184 reachedEndOfObject =
true;
191 <<
"Encountered object with embedded end-of-array marker";
192 Throw<std::runtime_error>(
"Illegal end-of-array marker in object");
200 <<
"Unknown field: field_type=" << type
201 <<
", field_name=" << field;
202 Throw<std::runtime_error> (
"Unknown field");
206 v_.emplace_back(sit, fn, depth+1);
209 if (
auto const obj =
dynamic_cast<STObject*
>(&(v_.back().get())))
210 obj->applyTemplateFromSField (fn);
215 auto const sf = getSortedFields(*
this, withAllFields);
219 { return lhs->getFName() == rhs->getFName(); });
221 if (dup != sf.cend())
222 Throw<std::runtime_error> (
"Duplicate field detected");
224 return reachedEndOfObject;
249 for (
auto const& elem :
v_)
258 ret += elem->getFullText ();
270 for (
auto const& elem :
v_)
278 ret += elem->getText ();
296 return (st1.getSType() == st2.getSType()) && st1.isEquivalent(st2);
303 return std::equal (sf1.begin (), sf1.end (), sf2.begin (), sf2.end (),
306 return (st1->getSType() == st2->getSType()) && st1->isEquivalent (*st2);
328 if (
mType !=
nullptr)
332 for (
auto const& elem :
v_)
334 if (elem->getFName () == field)
364 return v_[index]->getFName ();
383 if (createOkay &&
isFree ())
404 return peekField<STObject> (field);
409 return peekField<STArray> (field);
504 return getFieldByValue <STUInt8> (field);
509 return getFieldByValue <STUInt16> (field);
514 return getFieldByValue <STUInt32> (field);
519 return getFieldByValue <STUInt64> (field);
524 return getFieldByValue <STHash128> (field);
529 return getFieldByValue <STHash160> (field);
534 return getFieldByValue <STHash256> (field);
539 return getFieldByValue <STAccount> (field);
545 STBlob const& b = getFieldByConstRef <STBlob> (field,
empty);
552 return getFieldByConstRef <STAmount> (field,
empty);
558 return getFieldByConstRef <STPathSet> (field,
empty);
564 return getFieldByConstRef <STVector256> (field,
empty);
570 return getFieldByConstRef <STArray> (field,
empty);
580 v_[i] = std::move(*v);
585 Throw<std::runtime_error> (
586 "missing field in templated STObject");
593 setFieldUsingSetValue <STUInt8> (field, v);
598 setFieldUsingSetValue <STUInt16> (field, v);
603 setFieldUsingSetValue <STUInt32> (field, v);
608 setFieldUsingSetValue <STUInt64> (field, v);
613 setFieldUsingSetValue <STHash128> (field, v);
618 setFieldUsingSetValue <STHash256> (field, v);
623 setFieldUsingSetValue <STVector256> (field, v);
628 setFieldUsingSetValue <STAccount> (field, v);
633 setFieldUsingSetValue <STBlob> (field,
Buffer(v.
data (), v.
size ()));
638 setFieldUsingSetValue <STBlob>
661 for (
auto const& elem :
v_)
664 ret [elem->getFName().getJsonName()] = elem->getJson (options);
674 for (
auto const& t1 :
v_)
676 if ((t1->getSType () !=
STI_NOTPRESENT) && t1->getFName ().isBinary ())
680 for (
auto const& t2 : obj.
v_)
682 if (t1->getFName () == t2->getFName ())
699 for (
auto const& t2 : obj.
v_)
701 if ((t2->getSType () !=
STI_NOTPRESENT) && t2->getFName ().isBinary ())
719 for (
STBase const*
const field : fields)
727 field->addFieldID (s);
756 return lhs->getFName().fieldCode < rhs->getFName().fieldCode;
SField const & getFieldSType(int index) const
std::size_t size() const noexcept
Returns the number of bytes in the storage.
const STBase & peekAtField(SField const &field) const
STBase & getIndex(int offset)
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
void setAccountID(SField const &field, AccountID const &)
std::uint8_t const * data() const
const STArray & getFieldArray(SField const &field) const
virtual SerializedTypeID getSType() const
void makeFieldAbsent(SField const &field)
defaultObject_t defaultObject
bool hasMatchingEntry(const STBase &)
void setFieldH128(SField const &field, uint128 const &)
void setFieldU16(SField const &field, std::uint16_t)
void setFieldV256(SField const &field, STVector256 const &v)
int addFieldID(int type, int name)
std::uint64_t getFieldU64(SField const &field) const
An immutable linear range of bytes.
const STVector256 & getFieldV256(SField const &field) const
unsigned char getFieldU8(SField const &field) const
const SF_U32 sfFlags(access, STI_UINT32, 2, "Flags")
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
uint128 getFieldH128(SField const &field) const
Like std::vector<char> but better.
static const SField & getField(int fieldCode)
void setFieldVL(SField const &field, Blob const &)
Blob getFieldVL(SField const &field) const
uint256 getSHA512Half() const
const STBase * peekAtPIndex(int offset) const
uint160 getFieldH160(SField const &field) const
const STBase & peekAtIndex(int offset) const
beast::Journal debugLog()
Returns a debug journal.
virtual std::string getFullText() const override
virtual bool isEquivalent(const STBase &t) const override
STObject & operator=(STObject const &)=default
bool delField(SField const &field)
Defines the fields and their attributes within a STObject.
nonPresentObject_t nonPresentObject
void setFieldArray(SField const &field, STArray const &v)
@ objectValue
object value (collection of name/value pairs).
void applyTemplate(const SOTemplate &type) noexcept(false)
HashPrefix
Prefix for hashing functions.
void setFieldU8(SField const &field, unsigned char)
STArray & peekFieldArray(SField const &field)
bool operator==(const STObject &o) const
void setFieldAmount(SField const &field, STAmount const &)
AccountID getAccountID(SField const &field) const
void setFieldH256(SField const &field, uint256 const &)
void throwFieldNotFound(SField const &field)
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
bool clearFlag(std::uint32_t)
std::uint32_t getFlags() const
void setFName(SField const &n)
A STBase is a field.
std::uint16_t getFieldU16(SField const &field) const
void setFieldUsingAssignment(SField const &field, T const &value)
STBase * getPField(SField const &field, bool createOkay=false)
void setFieldPathSet(SField const &field, STPathSet const &)
bool shouldInclude(bool withSigningField) const
SField const & getFName() const
int getIndex(SField const &) const
Retrieve the position of a named field.
int getFieldIndex(SField const &field) const
STBase * makeFieldPresent(SField const &field)
std::size_t emplace_back(Args &&... args)
void applyTemplateFromSField(SField const &) noexcept(false)
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
STObject & peekFieldObject(SField const &field)
uint256 getSigningHash(HashPrefix prefix) const
const STBase * peekAtPField(SField const &field) const
virtual void add(Serializer &s) const override
A type which can be exported to a well known binary format.
STBase & getField(SField const &field)
std::string const & getName() const
bool isFieldPresent(SField const &field) const
STBase * getPIndex(int offset)
T adjacent_find(T... args)
bool setFlag(std::uint32_t)
bool isFlag(std::uint32_t) const
std::vector< unsigned char > Blob
Storage for linear binary data.
value_type value() const noexcept
std::uint32_t getFieldU32(SField const &field) const
bool matches(char const *string, char const *regex)
Return true if the string loosely matches the regex.
void setFieldU64(SField const &field, std::uint64_t)
virtual Json::Value getJson(JsonOptions options) const override
STPathSet const & getFieldPathSet(SField const &field) const
void set(const SOTemplate &)
void setFieldU32(SField const &field, std::uint32_t)
STAmount const & getFieldAmount(SField const &field) const
uint256 getHash(HashPrefix prefix) const
virtual std::string getText() const override
uint256 getFieldH256(SField const &field) const