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)
53 :
STBase(name), mType(nullptr)
56 Throw<std::runtime_error>(
"Maximum nesting depth of STObject exceeded");
69 return emplace(n, buf, std::move(*
this));
95 v_ = std::move(other.v_);
106 for (
auto const& elem : type)
118 auto throwFieldErr = [](
std::string const& field,
char const* description) {
120 ss <<
"Field '" << field <<
"' " << description;
122 JLOG(
debugLog().error()) <<
"STObject::applyTemplate failed: " << text;
123 Throw<FieldErr>(text);
128 v.reserve(type.size());
129 for (
auto const& e : type)
133 return b.get().getFName() == e.sField();
135 if (iter !=
v_.
end())
137 if ((e.style() ==
soeDEFAULT) && iter->get().isDefault())
140 e.sField().fieldName,
141 "may not be explicitly set to default.");
143 v.emplace_back(std::move(*iter));
150 throwFieldErr(e.sField().fieldName,
"is required but missing.");
155 for (
auto const& e :
v_)
158 if (!e->getFName().isDiscardable())
161 e->getFName().getName(),
"found in disallowed location.");
182 bool reachedEndOfObject =
false;
199 reachedEndOfObject =
true;
206 <<
"Encountered object with embedded end-of-array marker";
207 Throw<std::runtime_error>(
"Illegal end-of-array marker in object");
214 JLOG(
debugLog().error()) <<
"Unknown field: field_type=" << type
215 <<
", field_name=" << field;
216 Throw<std::runtime_error>(
"Unknown field");
224 obj->applyTemplateFromSField(fn);
232 sf.cbegin(), sf.cend(), [](
STBase const* lhs,
STBase const* rhs) {
233 return lhs->getFName() == rhs->getFName();
236 if (dup != sf.cend())
237 Throw<std::runtime_error>(
"Duplicate field detected");
239 return reachedEndOfObject;
267 for (
auto const& elem :
v_)
276 ret += elem->getFullText();
289 for (
auto const& elem :
v_)
297 ret += elem->getText();
319 return (st1.getSType() == st2.getSType()) &&
320 st1.isEquivalent(st2);
333 return (st1->getSType() == st2->getSType()) &&
334 st1->isEquivalent(*st2);
359 if (
mType !=
nullptr)
363 for (
auto const& elem :
v_)
365 if (elem->getFName() == field)
397 return v_[index]->getFName();
418 if (createOkay &&
isFree())
441 return peekField<STObject>(field);
447 return peekField<STArray>(field);
549 return getFieldByValue<STUInt8>(field);
555 return getFieldByValue<STUInt16>(field);
561 return getFieldByValue<STUInt32>(field);
567 return getFieldByValue<STUInt64>(field);
573 return getFieldByValue<STUInt128>(field);
579 return getFieldByValue<STUInt160>(field);
585 return getFieldByValue<STUInt256>(field);
591 return getFieldByValue<STAccount>(field);
598 STBlob const& b = getFieldByConstRef<STBlob>(field,
empty);
606 return getFieldByConstRef<STAmount>(field,
empty);
613 return getFieldByConstRef<STPathSet>(field,
empty);
620 return getFieldByConstRef<STVector256>(field,
empty);
627 return getFieldByConstRef<STArray>(field,
empty);
636 v_[i] = std::move(*v);
641 Throw<std::runtime_error>(
"missing field in templated STObject");
649 setFieldUsingSetValue<STUInt8>(field, v);
655 setFieldUsingSetValue<STUInt16>(field, v);
661 setFieldUsingSetValue<STUInt32>(field, v);
667 setFieldUsingSetValue<STUInt64>(field, v);
673 setFieldUsingSetValue<STUInt128>(field, v);
679 setFieldUsingSetValue<STUInt256>(field, v);
685 setFieldUsingSetValue<STVector256>(field, v);
691 setFieldUsingSetValue<STAccount>(field, v);
729 for (
auto const& elem :
v_)
732 ret[elem->getFName().getJsonName()] = elem->getJson(options);
743 for (
auto const& t1 :
v_)
745 if ((t1->getSType() !=
STI_NOTPRESENT) && t1->getFName().isBinary())
749 for (
auto const& t2 : obj.
v_)
751 if (t1->getFName() == t2->getFName())
768 for (
auto const& t2 : obj.
v_)
770 if ((t2->getSType() !=
STI_NOTPRESENT) && t2->getFName().isBinary())
789 for (
STBase const*
const field : fields)
798 field->addFieldID(s);
824 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 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 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.
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
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)
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)
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
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
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