aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Local/FSTLevelDBQueryCache.mm
diff options
context:
space:
mode:
Diffstat (limited to 'Firestore/Source/Local/FSTLevelDBQueryCache.mm')
-rw-r--r--Firestore/Source/Local/FSTLevelDBQueryCache.mm25
1 files changed, 25 insertions, 0 deletions
diff --git a/Firestore/Source/Local/FSTLevelDBQueryCache.mm b/Firestore/Source/Local/FSTLevelDBQueryCache.mm
index fe1bf19..95b032e 100644
--- a/Firestore/Source/Local/FSTLevelDBQueryCache.mm
+++ b/Firestore/Source/Local/FSTLevelDBQueryCache.mm
@@ -31,6 +31,7 @@
NS_ASSUME_NONNULL_BEGIN
+using firebase::firestore::local::LevelDbTransaction;
using Firestore::StringView;
using leveldb::DB;
using leveldb::Iterator;
@@ -59,6 +60,30 @@ using leveldb::WriteOptions;
FSTSnapshotVersion *_lastRemoteSnapshotVersion;
}
++ (nullable FSTPBTargetGlobal *)readTargetMetadataWithTransaction:
+ (firebase::firestore::local::LevelDbTransaction *)transaction {
+ std::string key = [FSTLevelDBTargetGlobalKey key];
+ std::string value;
+ Status status = transaction->Get(key, &value);
+ if (status.IsNotFound()) {
+ return nil;
+ } else if (!status.ok()) {
+ FSTFail(@"metadataForKey: failed loading key %s with status: %s", key.c_str(),
+ status.ToString().c_str());
+ }
+
+ NSData *data =
+ [[NSData alloc] initWithBytesNoCopy:(void *)value.data() length:value.size() freeWhenDone:NO];
+
+ NSError *error;
+ FSTPBTargetGlobal *proto = [FSTPBTargetGlobal parseFromData:data error:&error];
+ if (!proto) {
+ FSTFail(@"FSTPBTargetGlobal failed to parse: %@", error);
+ }
+
+ return proto;
+}
+
+ (nullable FSTPBTargetGlobal *)readTargetMetadataFromDB:(std::shared_ptr<DB>)db {
std::string key = [FSTLevelDBTargetGlobalKey key];
std::string value;