20 #include <ripple/basics/Log.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/protocol/STObject.h>
39 :
STBase(other.getFName()), v_(
std::move(other.v_)), mType(other.mType)
57 SField const& name) noexcept(
false)
60 v_.reserve(type.
size());
67 :
STBase(name), mType(nullptr)
70 Throw<std::runtime_error>(
"Maximum nesting depth of STObject exceeded");
79 v_ = std::move(other.v_);
90 for (
auto const& elem : type)
102 auto throwFieldErr = [](
std::string const& field,
char const* description) {
104 ss <<
"Field '" << field <<
"' " << description;
106 JLOG(
debugLog().error()) <<
"STObject::applyTemplate failed: " << text;
107 Throw<FieldErr>(text);
113 for (
auto const& e : type)
117 return b.get().getFName() == e.sField();
119 if (iter != v_.end())
121 if ((e.style() ==
soeDEFAULT) && iter->get().isDefault())
124 e.sField().fieldName,
125 "may not be explicitly set to default.");
127 v.emplace_back(std::move(*iter));
134 throwFieldErr(e.sField().fieldName,
"is required but missing.");
139 for (
auto const& e : v_)
142 if (!e->getFName().isDiscardable())
145 e->getFName().getName(),
"found in disallowed location.");
159 applyTemplate(*elements);
166 bool reachedEndOfObject =
false;
177 sit.getFieldID(type, field);
183 reachedEndOfObject =
true;
190 <<
"Encountered object with embedded end-of-array marker";
191 Throw<std::runtime_error>(
"Illegal end-of-array marker in object");
198 JLOG(
debugLog().error()) <<
"Unknown field: field_type=" << type
199 <<
", field_name=" << field;
200 Throw<std::runtime_error>(
"Unknown field");
204 v_.emplace_back(sit, fn, depth + 1);
207 if (
auto const obj =
dynamic_cast<STObject*
>(&(v_.back().get())))
208 obj->applyTemplateFromSField(fn);
213 auto const sf = getSortedFields(*
this, withAllFields);
216 sf.cbegin(), sf.cend(), [](
STBase const* lhs,
STBase const* rhs) {
217 return lhs->getFName() == rhs->getFName();
220 if (dup != sf.cend())
221 Throw<std::runtime_error>(
"Duplicate field detected");
223 return reachedEndOfObject;
251 for (
auto const& elem :
v_)
260 ret += elem->getFullText();
273 for (
auto const& elem :
v_)
281 ret += elem->getText();
303 return (st1.getSType() == st2.getSType()) &&
304 st1.isEquivalent(st2);
317 return (st1->getSType() == st2->getSType()) &&
318 st1->isEquivalent(*st2);
343 if (
mType !=
nullptr)
347 for (
auto const& elem :
v_)
349 if (elem->getFName() == field)
381 return v_[index]->getFName();
402 if (createOkay &&
isFree())
425 return peekField<STObject>(field);
431 return peekField<STArray>(field);
533 return getFieldByValue<STUInt8>(field);
539 return getFieldByValue<STUInt16>(field);
545 return getFieldByValue<STUInt32>(field);
551 return getFieldByValue<STUInt64>(field);
557 return getFieldByValue<STHash128>(field);
563 return getFieldByValue<STHash160>(field);
569 return getFieldByValue<STHash256>(field);
575 return getFieldByValue<STAccount>(field);
582 STBlob const& b = getFieldByConstRef<STBlob>(field,
empty);
590 return getFieldByConstRef<STAmount>(field,
empty);
597 return getFieldByConstRef<STPathSet>(field,
empty);
604 return getFieldByConstRef<STVector256>(field,
empty);
611 return getFieldByConstRef<STArray>(field,
empty);
620 v_[i] = std::move(*v);
625 Throw<std::runtime_error>(
"missing field in templated STObject");
633 setFieldUsingSetValue<STUInt8>(field, v);
639 setFieldUsingSetValue<STUInt16>(field, v);
645 setFieldUsingSetValue<STUInt32>(field, v);
651 setFieldUsingSetValue<STUInt64>(field, v);
657 setFieldUsingSetValue<STHash128>(field, v);
663 setFieldUsingSetValue<STHash256>(field, v);
669 setFieldUsingSetValue<STVector256>(field, v);
675 setFieldUsingSetValue<STAccount>(field, v);
713 for (
auto const& elem :
v_)
716 ret[elem->getFName().getJsonName()] = elem->getJson(options);
727 for (
auto const& t1 :
v_)
729 if ((t1->getSType() !=
STI_NOTPRESENT) && t1->getFName().isBinary())
733 for (
auto const& t2 : obj.
v_)
735 if (t1->getFName() == t2->getFName())
752 for (
auto const& t2 : obj.
v_)
754 if ((t2->getSType() !=
STI_NOTPRESENT) && t2->getFName().isBinary())
773 for (
STBase const*
const field : fields)
782 field->addFieldID(s);
808 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
std::vector< unsigned char > Blob
Storage for linear binary data.
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
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