20 #include <ripple/basics/Log.h>
21 #include <ripple/protocol/Feature.h>
22 #include <ripple/protocol/InnerObjectFormats.h>
23 #include <ripple/protocol/Rules.h>
24 #include <ripple/protocol/STAccount.h>
25 #include <ripple/protocol/STArray.h>
26 #include <ripple/protocol/STBlob.h>
27 #include <ripple/protocol/STCurrency.h>
28 #include <ripple/protocol/STObject.h>
33 :
STBase(other.getFName()), v_(
std::move(other.v_)), mType(other.mType)
56 :
STBase(name), mType(nullptr)
59 Throw<std::runtime_error>(
"Maximum nesting depth of STObject exceeded");
85 return emplace(n, buf, std::move(*
this));
111 v_ = std::move(other.v_);
122 for (
auto const& elem : type)
134 auto throwFieldErr = [](
std::string const& field,
char const* description) {
136 ss <<
"Field '" << field <<
"' " << description;
138 JLOG(
debugLog().error()) <<
"STObject::applyTemplate failed: " << text;
139 Throw<FieldErr>(text);
144 v.reserve(type.size());
145 for (
auto const& e : type)
149 return b.get().getFName() == e.sField();
151 if (iter !=
v_.
end())
153 if ((e.style() ==
soeDEFAULT) && iter->get().isDefault())
156 e.sField().fieldName,
157 "may not be explicitly set to default.");
159 v.emplace_back(std::move(*iter));
166 throwFieldErr(e.sField().fieldName,
"is required but missing.");
171 for (
auto const& e :
v_)
174 if (!e->getFName().isDiscardable())
177 e->getFName().getName(),
"found in disallowed location.");
198 bool reachedEndOfObject =
false;
213 if (type == STI_OBJECT && field == 1)
215 reachedEndOfObject =
true;
219 if (type == STI_ARRAY && field == 1)
222 <<
"Encountered object with embedded end-of-array marker";
223 Throw<std::runtime_error>(
"Illegal end-of-array marker in object");
230 JLOG(
debugLog().error()) <<
"Unknown field: field_type=" << type
231 <<
", field_name=" << field;
232 Throw<std::runtime_error>(
"Unknown field");
240 obj->applyTemplateFromSField(fn);
248 sf.cbegin(), sf.cend(), [](
STBase const* lhs,
STBase const* rhs) {
249 return lhs->getFName() == rhs->getFName();
252 if (dup != sf.cend())
253 Throw<std::runtime_error>(
"Duplicate field detected");
255 return reachedEndOfObject;
283 for (
auto const& elem :
v_)
285 if (elem->getSType() != STI_NOTPRESENT)
292 ret += elem->getFullText();
305 for (
auto const& elem :
v_)
313 ret += elem->getText();
335 return (st1.getSType() == st2.getSType()) &&
336 st1.isEquivalent(st2);
349 return (st1->getSType() == st2->getSType()) &&
350 st1->isEquivalent(*st2);
375 if (
mType !=
nullptr)
379 for (
auto const& elem :
v_)
381 if (elem->getFName() == field)
413 return v_[index]->getFName();
434 if (createOkay &&
isFree())
457 return peekField<STObject>(field);
463 return peekField<STArray>(field);
522 if (f->
getSType() != STI_NOTPRESENT)
565 return getFieldByValue<STUInt8>(field);
571 return getFieldByValue<STUInt16>(field);
577 return getFieldByValue<STUInt32>(field);
583 return getFieldByValue<STUInt64>(field);
589 return getFieldByValue<STUInt128>(field);
595 return getFieldByValue<STUInt160>(field);
601 return getFieldByValue<STUInt256>(field);
607 return getFieldByValue<STAccount>(field);
614 STBlob const& b = getFieldByConstRef<STBlob>(field,
empty);
622 return getFieldByConstRef<STAmount>(field,
empty);
629 return getFieldByConstRef<STPathSet>(field,
empty);
636 return getFieldByConstRef<STVector256>(field,
empty);
643 return getFieldByConstRef<STArray>(field,
empty);
650 return getFieldByConstRef<STCurrency>(field,
empty);
665 v_[i] = std::move(v);
670 Throw<std::runtime_error>(
"missing field in templated STObject");
678 setFieldUsingSetValue<STUInt8>(field, v);
684 setFieldUsingSetValue<STUInt16>(field, v);
690 setFieldUsingSetValue<STUInt32>(field, v);
696 setFieldUsingSetValue<STUInt64>(field, v);
702 setFieldUsingSetValue<STUInt128>(field, v);
708 setFieldUsingSetValue<STUInt256>(field, v);
714 setFieldUsingSetValue<STVector256>(field, v);
720 setFieldUsingSetValue<STAccount>(field, v);
770 for (
auto const& elem :
v_)
772 if (elem->getSType() != STI_NOTPRESENT)
773 ret[elem->getFName().getJsonName()] = elem->getJson(options);
784 for (
auto const& t1 :
v_)
786 if ((t1->getSType() != STI_NOTPRESENT) && t1->getFName().isBinary())
790 for (
auto const& t2 : obj.
v_)
792 if (t1->getFName() == t2->getFName())
809 for (
auto const& t2 : obj.
v_)
811 if ((t2->getSType() != STI_NOTPRESENT) && t2->getFName().isBinary())
830 for (
STBase const*
const field : fields)
837 (sType != STI_OBJECT) ||
838 (field->getFName().fieldType == STI_OBJECT));
839 field->addFieldID(s);
841 if (sType == STI_ARRAY || sType == STI_OBJECT)
856 if ((base.
getSType() != STI_NOTPRESENT) &&
865 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
static std::vector< STBase const * > getSortedFields(STObject const &objToSort, WhichFields whichFields)
void setAccountID(SField const &field, AccountID const &)
STObject(STObject const &)=default
const STArray & getFieldArray(SField const &field) const
void applyTemplate(const SOTemplate &type)
std::vector< unsigned char > Blob
Storage for linear binary data.
virtual SerializedTypeID getSType() const
void makeFieldAbsent(SField const &field)
defaultObject_t defaultObject
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
bool hasMatchingEntry(const STBase &)
void setFieldH128(SField const &field, uint128 const &)
void setFieldU16(SField const &field, std::uint16_t)
void setFieldIssue(SField const &field, STIssue const &)
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 STBase * peekAtPIndex(int offset) const
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.
void getFieldID(int &type, int &name)
uint128 getFieldH128(SField const &field) const
Like std::vector<char> but better.
void setFieldCurrency(SField const &field, STCurrency const &)
STBase * move(std::size_t n, void *buf) override
static const SField & getField(int fieldCode)
void setFieldVL(SField const &field, Blob const &)
Blob getFieldVL(SField const &field) const
bool isDefault() const override
uint256 getSHA512Half() const
uint160 getFieldH160(SField const &field) const
const STCurrency & getFieldCurrency(SField const &field) const
beast::Journal debugLog()
Returns a debug journal.
std::string getFullText() const override
bool isEquivalent(const STBase &t) const override
const STBase & peekAtIndex(int offset) const
STObject & operator=(STObject const &)=default
bool delField(SField const &field)
STBase * copy(std::size_t n, void *buf) const override
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).
HashPrefix
Prefix for hashing functions.
static STBase * emplace(std::size_t n, void *buf, T &&val)
static STObject makeInnerObject(SField const &name, Rules const &rules)
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 &)
value_type value() const noexcept
std::size_t empty() const noexcept
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 add(Serializer &s) const override
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
STBase & getIndex(int offset)
STObject & peekFieldObject(SField const &field)
Note, should be treated as flags that can be | and &.
uint256 getSigningHash(HashPrefix prefix) const
const STBase * peekAtPField(SField const &field) const
A type which can be exported to a well known binary format.
STBase & getField(SField const &field)
SerializedTypeID getSType() const override
std::string const & getName() const
bool isFieldPresent(SField const &field) const
T adjacent_find(T... args)
bool setFlag(std::uint32_t)
bool isFlag(std::uint32_t) const
Rules controlling protocol behavior.
void applyTemplateFromSField(SField const &)
int add32(std::uint32_t i)
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)
Json::Value getJson(JsonOptions options) const override
STPathSet const & getFieldPathSet(SField const &field) const
const uint256 fixInnerObjTemplate
void set(const SOTemplate &)
void setFieldU32(SField const &field, std::uint32_t)
STAmount const & getFieldAmount(SField const &field) const
STBase * getPIndex(int offset)
uint256 getHash(HashPrefix prefix) const
std::string getText() const override
uint256 getFieldH256(SField const &field) const
std::uint8_t const * data() const