diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-04-22 15:56:42 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-04-22 15:56:42 +0300 |
commit | 79a3243c22632c117f7ce4612002d6989ec99d1c (patch) | |
tree | 003a7ca4f76a2a24440558e1a856ecd9019c45c6 /src/ObjectModel | |
parent | 2fd30e46c68744f9f8aae0d645a2136e1e914689 (diff) |
Don't return "next" in rr_model unless the result is an array
Diffstat (limited to 'src/ObjectModel')
-rw-r--r-- | src/ObjectModel/ObjectModel.cpp | 11 | ||||
-rw-r--r-- | src/ObjectModel/ObjectModel.h | 7 |
2 files changed, 8 insertions, 10 deletions
diff --git a/src/ObjectModel/ObjectModel.cpp b/src/ObjectModel/ObjectModel.cpp index 324282f0..14f458d0 100644 --- a/src/ObjectModel/ObjectModel.cpp +++ b/src/ObjectModel/ObjectModel.cpp @@ -266,8 +266,8 @@ ObjectModel::ObjectModel() noexcept // ObjectExplorationContext members // Constructor used when reporting the OM as JSON -ObjectExplorationContext::ObjectExplorationContext(bool wal, const char *reportFlags, unsigned int initialMaxDepth) noexcept - : startMillis(millis()), maxDepth(initialMaxDepth), currentDepth(0), startElement(0), nextElement(-1), arraysBeingIterated(0), numIndicesProvided(0), numIndicesCounted(0), +ObjectExplorationContext::ObjectExplorationContext(bool wal, const char *reportFlags, unsigned int initialMaxDepth, size_t initialBufferOffset) noexcept + : startMillis(millis()), initialBufOffset(initialBufferOffset), maxDepth(initialMaxDepth), currentDepth(0), startElement(0), nextElement(-1), numIndicesProvided(0), numIndicesCounted(0), line(-1), column(-1), shortForm(false), onlyLive(false), includeVerbose(false), wantArrayLength(wal), includeNulls(false), includeObsolete(false), obsoleteFieldQueried(false), wantExists(false) { @@ -320,7 +320,7 @@ ObjectExplorationContext::ObjectExplorationContext(bool wal, const char *reportF // Constructor when evaluating expressions ObjectExplorationContext::ObjectExplorationContext(bool wal, bool wex, int p_line, int p_col) noexcept - : startMillis(millis()), maxDepth(99), currentDepth(0), startElement(0), nextElement(-1), arraysBeingIterated(0), numIndicesProvided(0), numIndicesCounted(0), + : startMillis(millis()), initialBufOffset(0), maxDepth(99), currentDepth(0), startElement(0), nextElement(-1), numIndicesProvided(0), numIndicesCounted(0), line(p_line), column(p_col), shortForm(false), onlyLive(false), includeVerbose(true), wantArrayLength(wal), includeNulls(false), includeObsolete(true), obsoleteFieldQueried(false), wantExists(wex) { @@ -428,7 +428,7 @@ void ObjectModel::ReportAsJson(OutputBuffer* buf, ObjectExplorationContext& cont void ObjectModel::ReportAsJson(OutputBuffer *buf, const char *filter, const char *reportFlags, bool wantArrayLength) const THROWS(GCodeException) { const unsigned int defaultMaxDepth = (wantArrayLength) ? 99 : (filter[0] == 0) ? 1 : 99; - ObjectExplorationContext context(wantArrayLength, reportFlags, defaultMaxDepth); + ObjectExplorationContext context(wantArrayLength, reportFlags, defaultMaxDepth, buf->Length()); ReportAsJson(buf, context, nullptr, 0, filter); if (context.GetNextElement() >= 0) { @@ -725,11 +725,11 @@ void ObjectModel::ReportItemAsJsonFull(OutputBuffer *buf, ObjectExplorationConte void ObjectModel::ReportArrayAsJson(OutputBuffer *buf, ObjectExplorationContext& context, const ObjectModelClassDescriptor *classDescriptor, const ObjectModelArrayDescriptor *omad, const char *filter) const THROWS(GCodeException) { + const bool isRootArray = (buf->Length() == context.GetInitialBufferOffset()); // it's a root array if we haven't started writing to the buffer yet ReadLocker lock(omad->lockPointer); buf->cat('['); const size_t count = omad->GetNumElements(this, context); - const bool isRootArray = context.IncreaseArraysIterated(); const size_t startElement = (isRootArray) ? context.GetStartElement() : 0; for (size_t i = startElement; i < count; ++i) { @@ -753,7 +753,6 @@ void ObjectModel::ReportArrayAsJson(OutputBuffer *buf, ObjectExplorationContext& { context.SetNextElement(0); } - context.DecreaseArraysIterated(); buf->cat(']'); } diff --git a/src/ObjectModel/ObjectModel.h b/src/ObjectModel/ObjectModel.h index 1ac5e416..24f810d3 100644 --- a/src/ObjectModel/ObjectModel.h +++ b/src/ObjectModel/ObjectModel.h @@ -188,7 +188,7 @@ class ObjectExplorationContext { public: // Constructor used when reporting the OM as JSON - ObjectExplorationContext(bool wal, const char *reportFlags, unsigned int initialMaxDepth) noexcept; + ObjectExplorationContext(bool wal, const char *reportFlags, unsigned int initialMaxDepth, size_t initialBufferOffset) noexcept; // Constructor used when evaluating expressions ObjectExplorationContext(bool wal, bool wex, int p_line, int p_col) noexcept; @@ -196,8 +196,6 @@ public: void SetMaxDepth(unsigned int d) noexcept { maxDepth = d; } bool IncreaseDepth() noexcept { if (currentDepth < maxDepth) { ++currentDepth; return true; } return false; } void DecreaseDepth() noexcept { --currentDepth; } - bool IncreaseArraysIterated() noexcept { ++arraysBeingIterated; return arraysBeingIterated == 1; } - void DecreaseArraysIterated() noexcept { --arraysBeingIterated; } void AddIndex(int32_t index) THROWS(GCodeException); void AddIndex() THROWS(GCodeException); void RemoveIndex() THROWS(GCodeException); @@ -214,6 +212,7 @@ public: bool WantExists() const noexcept { return wantExists; } bool ShouldIncludeNulls() const noexcept { return includeNulls; } uint64_t GetStartMillis() const { return startMillis; } + size_t GetInitialBufferOffset() const noexcept { return initialBufOffset; } bool ObsoleteFieldQueried() const noexcept { return obsoleteFieldQueried; } void SetObsoleteFieldQueried() noexcept { obsoleteFieldQueried = true; } @@ -225,11 +224,11 @@ private: static constexpr size_t MaxIndices = 4; // max depth of array nesting uint64_t startMillis; // the milliseconds counter when we started exploring the OM. Stored so that upTime and msUpTime are consistent. + size_t initialBufOffset; unsigned int maxDepth; unsigned int currentDepth; unsigned int startElement; int nextElement; - unsigned int arraysBeingIterated; size_t numIndicesProvided; // the number of indices provided, when we are doing a value lookup size_t numIndicesCounted; // the number of indices passed in the search string int32_t indices[MaxIndices]; |