diff options
author | zxu <zxu@google.com> | 2018-03-14 08:57:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-14 08:57:31 -0400 |
commit | 9e815620e9f7f43b42e03db4e5118d7ad03ddee7 (patch) | |
tree | 86f362bad99281325fca7ee3ae116b6a0f36d511 /Firestore/Source/Local/FSTLevelDBKey.mm | |
parent | d4d73ea53ecdf1e8ade3d00921419645dd5d66f7 (diff) |
grand PR to port the remaining paths (FieldPath and ResourcePath). (#865)
* naively remove FSTPath import and source/test files.
* port FieldPath, part I
* port FieldPath, part II
* port ResourcePath, part I
* port ResourcePath, part II
* the grand commit to fix build errors
* use testutil:: helper instead of those from FSTHelpers
* fix test and lint
* use c_str in errmsg directly
* fix
* fix
* make code clean
* fix integration test I missed
* fix to avoid naming collision in preprocessor
* address changes
* address changes
* address changes
* fix: fieldMask are actually shared with different context.
* address changes
* address changes
Diffstat (limited to 'Firestore/Source/Local/FSTLevelDBKey.mm')
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBKey.mm | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/Firestore/Source/Local/FSTLevelDBKey.mm b/Firestore/Source/Local/FSTLevelDBKey.mm index bd7b44a..e23f5b7 100644 --- a/Firestore/Source/Local/FSTLevelDBKey.mm +++ b/Firestore/Source/Local/FSTLevelDBKey.mm @@ -21,16 +21,19 @@ #include <vector> #import "Firestore/Source/Model/FSTDocumentKey.h" -#import "Firestore/Source/Model/FSTPath.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" #include "Firestore/core/src/firebase/firestore/util/ordered_code.h" +#include "Firestore/core/src/firebase/firestore/util/string_apple.h" + +namespace util = firebase::firestore::util; namespace util = firebase::firestore::util; using firebase::firestore::model::ResourcePath; NS_ASSUME_NONNULL_BEGIN +using firebase::firestore::model::ResourcePath; using firebase::firestore::util::OrderedCode; using Firestore::StringView; using leveldb::Slice; @@ -255,10 +258,10 @@ BOOL ReadLabeledStringMatching(Slice *contents, * For each segment in the given resource path writes an FSTComponentLabelPathSegment component * label and a string containing the path segment. */ -void WriteResourcePath(std::string *dest, FSTResourcePath *path) { - for (int i = 0; i < path.length; i++) { +void WriteResourcePath(std::string *dest, const ResourcePath &path) { + for (const auto &segment : path) { WriteComponentLabel(dest, FSTComponentLabelPathSegment); - OrderedCode::WriteString(dest, StringView([path segmentAtIndex:i])); + OrderedCode::WriteString(dest, segment); } } @@ -522,7 +525,8 @@ NSString *InvalidKey(const Slice &key) { return result; } -+ (std::string)keyPrefixWithUserID:(StringView)userID resourcePath:(FSTResourcePath *)resourcePath { ++ (std::string)keyPrefixWithUserID:(StringView)userID + resourcePath:(const ResourcePath &)resourcePath { std::string result; WriteTableName(&result, kDocumentMutationsTable); WriteUserID(&result, userID); @@ -536,7 +540,7 @@ NSString *InvalidKey(const Slice &key) { std::string result; WriteTableName(&result, kDocumentMutationsTable); WriteUserID(&result, userID); - WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]); + WriteResourcePath(&result, documentKey.path); WriteBatchID(&result, batchID); WriteTerminator(&result); return result; @@ -690,7 +694,7 @@ NSString *InvalidKey(const Slice &key) { std::string result; WriteTableName(&result, kTargetDocumentsTable); WriteTargetID(&result, targetID); - WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]); + WriteResourcePath(&result, documentKey.path); WriteTerminator(&result); return result; } @@ -714,7 +718,7 @@ NSString *InvalidKey(const Slice &key) { return result; } -+ (std::string)keyPrefixWithResourcePath:(FSTResourcePath *)resourcePath { ++ (std::string)keyPrefixWithResourcePath:(const ResourcePath &)resourcePath { std::string result; WriteTableName(&result, kDocumentTargetsTable); WriteResourcePath(&result, resourcePath); @@ -724,7 +728,7 @@ NSString *InvalidKey(const Slice &key) { + (std::string)keyWithDocumentKey:(FSTDocumentKey *)documentKey targetID:(FSTTargetID)targetID { std::string result; WriteTableName(&result, kDocumentTargetsTable); - WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]); + WriteResourcePath(&result, documentKey.path); WriteTargetID(&result, targetID); WriteTerminator(&result); return result; @@ -749,7 +753,7 @@ NSString *InvalidKey(const Slice &key) { return result; } -+ (std::string)keyPrefixWithResourcePath:(FSTResourcePath *)path { ++ (std::string)keyPrefixWithResourcePath:(const ResourcePath &)path { std::string result; WriteTableName(&result, kRemoteDocumentsTable); WriteResourcePath(&result, path); @@ -759,7 +763,7 @@ NSString *InvalidKey(const Slice &key) { + (std::string)keyWithDocumentKey:(FSTDocumentKey *)key { std::string result; WriteTableName(&result, kRemoteDocumentsTable); - WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:key.path]); + WriteResourcePath(&result, key.path); WriteTerminator(&result); return result; } |