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>
30 :
STBase(other.getFName()), v_(
std::move(other.v_)), mType(other.mType)
46 SField const& name) noexcept(
false)
49 v_.reserve(type.
size());
56 :
STBase(name), mType(nullptr)
59 Throw<std::runtime_error>(
"Maximum nesting depth of STObject exceeded");
68 v_ = std::move(other.v_);
79 for (
auto const& elem : type)
91 auto throwFieldErr = [](
std::string const& field,
char const* description) {
93 ss <<
"Field '" << field <<
"' " << description;
95 JLOG(
debugLog().error()) <<
"STObject::applyTemplate failed: " << text;
96 Throw<FieldErr>(text);
102 for (
auto const& e : type)
106 return b.get().getFName() == e.sField();
108 if (iter != v_.end())
110 if ((e.style() ==
soeDEFAULT) && iter->get().isDefault())
113 e.sField().fieldName,
114 "may not be explicitly set to default.");
116 v.emplace_back(std::move(*iter));
123 throwFieldErr(e.sField().fieldName,
"is required but missing.");
128 for (
auto const& e : v_)
131 if (!e->getFName().isDiscardable())
134 e->getFName().getName(),
"found in disallowed location.");
148 applyTemplate(*elements);
155 bool reachedEndOfObject =
false;
166 sit.getFieldID(type, field);
172 reachedEndOfObject =
true;
179 <<
"Encountered object with embedded end-of-array marker";
180 Throw<std::runtime_error>(
"Illegal end-of-array marker in object");
187 JLOG(
debugLog().error()) <<
"Unknown field: field_type=" << type
188 <<
", field_name=" << field;
189 Throw<std::runtime_error>(
"Unknown field");
193 v_.emplace_back(sit, fn, depth + 1);
196 if (
auto const obj =
dynamic_cast<STObject*
>(&(v_.back().get())))
197 obj->applyTemplateFromSField(fn);
202 auto const sf = getSortedFields(*
this, withAllFields);
205 sf.cbegin(), sf.cend(), [](
STBase const* lhs,
STBase const* rhs) {
206 return lhs->getFName() == rhs->getFName();
209 if (dup != sf.cend())
210 Throw<std::runtime_error>(
"Duplicate field detected");
212 return reachedEndOfObject;
240 for (
auto const& elem :
v_)
249 ret += elem->getFullText();
262 for (
auto const& elem :
v_)
270 ret += elem->getText();
292 return (st1.getSType() == st2.getSType()) &&
293 st1.isEquivalent(st2);
306 return (st1->getSType() == st2->getSType()) &&
307 st1->isEquivalent(*st2);
332 if (
mType !=
nullptr)
336 for (
auto const& elem :
v_)
338 if (elem->getFName() == field)
370 return v_[index]->getFName();
391 if (createOkay &&
isFree())
414 return peekField<STObject>(field);
420 return peekField<STArray>(field);
522 return getFieldByValue<STUInt8>(field);
528 return getFieldByValue<STUInt16>(field);
534 return getFieldByValue<STUInt32>(field);
540 return getFieldByValue<STUInt64>(field);
546 return getFieldByValue<STHash128>(field);
552 return getFieldByValue<STHash160>(field);
558 return getFieldByValue<STHash256>(field);
564 return getFieldByValue<STAccount>(field);
571 STBlob const& b = getFieldByConstRef<STBlob>(field,
empty);
579 return getFieldByConstRef<STAmount>(field,
empty);
586 return getFieldByConstRef<STPathSet>(field,
empty);
593 return getFieldByConstRef<STVector256>(field,
empty);
600 return getFieldByConstRef<STArray>(field,
empty);
609 v_[i] = std::move(*v);
614 Throw<std::runtime_error>(
"missing field in templated STObject");
622 setFieldUsingSetValue<STUInt8>(field, v);
628 setFieldUsingSetValue<STUInt16>(field, v);
634 setFieldUsingSetValue<STUInt32>(field, v);
640 setFieldUsingSetValue<STUInt64>(field, v);
646 setFieldUsingSetValue<STHash128>(field, v);
652 setFieldUsingSetValue<STHash256>(field, v);
658 setFieldUsingSetValue<STVector256>(field, v);
664 setFieldUsingSetValue<STAccount>(field, v);
702 for (
auto const& elem :
v_)
705 ret[elem->getFName().getJsonName()] = elem->getJson(options);
716 for (
auto const& t1 :
v_)
718 if ((t1->getSType() !=
STI_NOTPRESENT) && t1->getFName().isBinary())
722 for (
auto const& t2 : obj.
v_)
724 if (t1->getFName() == t2->getFName())
741 for (
auto const& t2 : obj.
v_)
743 if ((t2->getSType() !=
STI_NOTPRESENT) && t2->getFName().isBinary())
762 for (
STBase const*
const field : fields)
771 field->addFieldID(s);
797 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
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
Integers of any length that is a multiple of 32-bits.
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
int add32(std::uint32_t i)
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