in Firestore/core/src/local/leveldb_key.cc [505:624]
std::string Reader::Describe() {
leveldb::Slice original = src_;
bool is_terminated = false;
std::string description;
absl::StrAppend(&description, "[");
while (!empty()) {
leveldb::Slice saved_source = src_;
ComponentLabel label = ReadComponentLabel();
if (!ok_) {
break;
}
if (label == ComponentLabel::Terminator) {
is_terminated = true;
break;
}
// Reset the reader since all the different read routines expect to see the
// separator first
src_ = saved_source;
if (label == ComponentLabel::PathSegment) {
ResourcePath resource_path = ReadResourcePath();
if (ok_) {
absl::StrAppend(&description,
" path=", resource_path.CanonicalString());
}
} else if (label == ComponentLabel::TableName) {
std::string table = ReadLabeledString(ComponentLabel::TableName);
if (ok_) {
absl::StrAppend(&description, table, ":");
}
} else if (label == ComponentLabel::BatchId) {
model::BatchId batch_id = ReadBatchId();
if (ok_) {
absl::StrAppend(&description, " batch_id=", batch_id);
}
} else if (label == ComponentLabel::CanonicalId) {
std::string canonical_id = ReadCanonicalId();
if (ok_) {
absl::StrAppend(&description, " canonical_id=", canonical_id);
}
} else if (label == ComponentLabel::TargetId) {
model::TargetId target_id = ReadTargetId();
if (ok_) {
absl::StrAppend(&description, " target_id=", target_id);
}
} else if (label == ComponentLabel::UserId) {
std::string user_id = ReadUserId();
if (ok_) {
absl::StrAppend(&description, " user_id=", user_id);
}
} else if (label == ComponentLabel::CollectionId) {
std::string collection_id = ReadCollectionId();
if (ok_) {
absl::StrAppend(&description, " collection_id=", collection_id);
}
} else if (label == ComponentLabel::DocumentId) {
std::string document_id = ReadDocumentId();
if (ok_) {
absl::StrAppend(&description, " document_id=", document_id);
}
} else if (label == ComponentLabel::SnapshotVersion) {
model::SnapshotVersion snapshot_version = ReadSnapshotVersion();
if (ok_) {
absl::StrAppend(&description,
" snapshot_version=", snapshot_version.ToString());
}
} else if (label == ComponentLabel::BundleId) {
std::string bundle_id = ReadBundleId();
if (ok_) {
absl::StrAppend(&description, " bundle_id=", bundle_id);
}
} else if (label == ComponentLabel::QueryName) {
std::string query_name = ReadQueryName();
if (ok_) {
absl::StrAppend(&description, " query_name=", query_name);
}
} else if (label == ComponentLabel::IndexId) {
int32_t index_id = ReadIndexId();
if (ok_) {
absl::StrAppend(&description, " index_id=", index_id);
}
} else if (label == ComponentLabel::IndexArrayValue) {
std::string value = ReadIndexArrayValue();
if (ok_) {
absl::StrAppend(&description, " array_value=", std::move(value));
}
} else if (label == ComponentLabel::IndexDirectionalValue) {
std::string value = ReadIndexDirectionalValue();
if (ok_) {
absl::StrAppend(&description, " directional_value=", std::move(value));
}
} else {
absl::StrAppend(&description, " unknown label=", static_cast<int>(label));
Fail();
}
}
if (!ok_ || !empty()) {
absl::StrAppend(&description, " invalid key=<", InvalidKey(original), ">");
} else if (!is_terminated) {
absl::StrAppend(&description, " incomplete key");
}
absl::StrAppend(&description, "]");
return description;
}