aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-04-25 14:13:57 -0400
committerGravatar GitHub <noreply@github.com>2018-04-25 14:13:57 -0400
commitff32b59036f35512c64fcd75ae5cee8aca228929 (patch)
tree9b09fff01e1ce3546c25f162f703b782c9fbca61 /Firestore/Source
parentf9bd6d3c9491dddbfc9cbe0fcc633030a66fe9da (diff)
Port `SnapshotVersion` for `Remote` (#1174)
* no-brainer replace FSTSnapshotVersion by SnapshotVersion in `Remote` * delete `FSTSnapshotVersion` in `Remote` * fix test * partially revert RemoteEvent * Revert "partially revert RemoteEvent" This reverts commit 67e35bb6c11eaf79608df8d02a60788a40331d0f. * fix a bug * fix integration * address changes
Diffstat (limited to 'Firestore/Source')
-rw-r--r--Firestore/Source/Core/FSTSyncEngine.mm8
-rw-r--r--Firestore/Source/Local/FSTLocalSerializer.mm15
-rw-r--r--Firestore/Source/Remote/FSTDatastore.h1
-rw-r--r--Firestore/Source/Remote/FSTRemoteEvent.h34
-rw-r--r--Firestore/Source/Remote/FSTRemoteEvent.mm63
-rw-r--r--Firestore/Source/Remote/FSTRemoteStore.mm15
-rw-r--r--Firestore/Source/Remote/FSTSerializerBeta.h15
-rw-r--r--Firestore/Source/Remote/FSTSerializerBeta.mm70
-rw-r--r--Firestore/Source/Remote/FSTStream.h7
-rw-r--r--Firestore/Source/Remote/FSTStream.mm6
-rw-r--r--Firestore/Source/Remote/FSTWatchChange.h1
11 files changed, 130 insertions, 105 deletions
diff --git a/Firestore/Source/Core/FSTSyncEngine.mm b/Firestore/Source/Core/FSTSyncEngine.mm
index 138fb41..8c2aeb2 100644
--- a/Firestore/Source/Core/FSTSyncEngine.mm
+++ b/Firestore/Source/Core/FSTSyncEngine.mm
@@ -45,11 +45,13 @@
#include "Firestore/core/src/firebase/firestore/auth/user.h"
#include "Firestore/core/src/firebase/firestore/core/target_id_generator.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
using firebase::firestore::auth::HashUser;
using firebase::firestore::auth::User;
using firebase::firestore::core::TargetIdGenerator;
using firebase::firestore::model::DocumentKey;
+using firebase::firestore::model::SnapshotVersion;
using firebase::firestore::model::TargetId;
NS_ASSUME_NONNULL_BEGIN
@@ -347,9 +349,9 @@ static const FSTListenSequenceNumber kIrrelevantSequenceNumber = -1;
[NSMutableDictionary dictionary];
FSTDeletedDocument *doc =
[FSTDeletedDocument documentWithKey:limboKey version:[FSTSnapshotVersion noVersion]];
- FSTRemoteEvent *event = [FSTRemoteEvent eventWithSnapshotVersion:[FSTSnapshotVersion noVersion]
- targetChanges:targetChanges
- documentUpdates:{{limboKey, doc}}];
+ FSTRemoteEvent *event = [[FSTRemoteEvent alloc] initWithSnapshotVersion:SnapshotVersion::None()
+ targetChanges:targetChanges
+ documentUpdates:{{limboKey, doc}}];
[self applyRemoteEvent:event];
} else {
FSTQueryView *queryView = self.queryViewsByTarget[@(targetID)];
diff --git a/Firestore/Source/Local/FSTLocalSerializer.mm b/Firestore/Source/Local/FSTLocalSerializer.mm
index d20f50b..652fa5f 100644
--- a/Firestore/Source/Local/FSTLocalSerializer.mm
+++ b/Firestore/Source/Local/FSTLocalSerializer.mm
@@ -30,9 +30,11 @@
#import "Firestore/Source/Remote/FSTSerializerBeta.h"
#import "Firestore/Source/Util/FSTAssert.h"
+#include "Firestore/core/include/firebase/firestore/timestamp.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
+using firebase::Timestamp;
using firebase::firestore::model::DocumentKey;
using firebase::firestore::model::SnapshotVersion;
@@ -130,7 +132,8 @@ using firebase::firestore::model::SnapshotVersion;
FSTPBWriteBatch *proto = [FSTPBWriteBatch message];
proto.batchId = batch.batchID;
- proto.localWriteTime = [remoteSerializer encodedTimestamp:batch.localWriteTime];
+ proto.localWriteTime = [remoteSerializer
+ encodedTimestamp:Timestamp{batch.localWriteTime.seconds, batch.localWriteTime.nanoseconds}];
NSMutableArray<GCFSWrite *> *writes = proto.writesArray;
for (FSTMutation *mutation in batch.mutations) {
@@ -148,11 +151,13 @@ using firebase::firestore::model::SnapshotVersion;
[mutations addObject:[remoteSerializer decodedMutation:write]];
}
- FIRTimestamp *localWriteTime = [remoteSerializer decodedTimestamp:batch.localWriteTime];
+ Timestamp localWriteTime = [remoteSerializer decodedTimestamp:batch.localWriteTime];
- return [[FSTMutationBatch alloc] initWithBatchID:batchID
- localWriteTime:localWriteTime
- mutations:mutations];
+ return [[FSTMutationBatch alloc]
+ initWithBatchID:batchID
+ localWriteTime:[FIRTimestamp timestampWithSeconds:localWriteTime.seconds()
+ nanoseconds:localWriteTime.nanoseconds()]
+ mutations:mutations];
}
- (FSTPBTarget *)encodedQueryData:(FSTQueryData *)queryData {
diff --git a/Firestore/Source/Remote/FSTDatastore.h b/Firestore/Source/Remote/FSTDatastore.h
index b3ba46c..da14b6e 100644
--- a/Firestore/Source/Remote/FSTDatastore.h
+++ b/Firestore/Source/Remote/FSTDatastore.h
@@ -31,7 +31,6 @@
@class FSTMutationResult;
@class FSTQueryData;
@class FSTSerializerBeta;
-@class FSTSnapshotVersion;
@class FSTWatchChange;
@class FSTWatchStream;
@class FSTWriteStream;
diff --git a/Firestore/Source/Remote/FSTRemoteEvent.h b/Firestore/Source/Remote/FSTRemoteEvent.h
index 0f6b6c7..0e25a2f 100644
--- a/Firestore/Source/Remote/FSTRemoteEvent.h
+++ b/Firestore/Source/Remote/FSTRemoteEvent.h
@@ -23,11 +23,11 @@
#import "Firestore/Source/Model/FSTDocumentKeySet.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
@class FSTDocument;
@class FSTExistenceFilter;
@class FSTMaybeDocument;
-@class FSTSnapshotVersion;
@class FSTWatchChange;
@class FSTQueryData;
@@ -107,6 +107,12 @@ typedef NS_ENUM(NSUInteger, FSTCurrentStatusUpdate) {
@interface FSTTargetChange : NSObject
/**
+ * Creates a new target change with the given SnapshotVersion.
+ */
+- (instancetype)initWithSnapshotVersion:
+ (firebase::firestore::model::SnapshotVersion)snapshotVersion;
+
+/**
* Creates a new target change with the given documents. Instances of FSTDocument are considered
* added. Instance of FSTDeletedDocument are considered removed. This is intended primarily for
* testing.
@@ -115,6 +121,12 @@ typedef NS_ENUM(NSUInteger, FSTCurrentStatusUpdate) {
currentStatusUpdate:(FSTCurrentStatusUpdate)currentStatusUpdate;
/**
+ * The snapshot version representing the last state at which this target received a consistent
+ * snapshot from the backend.
+ */
+- (const firebase::firestore::model::SnapshotVersion &)snapshotVersion;
+
+/**
* The new "current" (synced) status of this target. Set to CurrentStatusUpdateNone if the status
* should not be updated. Note "current" has special meaning for in the RPC protocol that implies
* that a target is both up-to-date and consistent with the rest of the watch stream.
@@ -125,12 +137,6 @@ typedef NS_ENUM(NSUInteger, FSTCurrentStatusUpdate) {
@property(nonatomic, strong, readonly) FSTTargetMapping *mapping;
/**
- * The snapshot version representing the last state at which this target received a consistent
- * snapshot from the backend.
- */
-@property(nonatomic, strong, readonly) FSTSnapshotVersion *snapshotVersion;
-
-/**
* An opaque, server-assigned token that allows watching a query to be resumed after disconnecting
* without retransmitting all the data that matches the query. The resume token essentially
* identifies a point in time from which the server should resume sending results.
@@ -147,14 +153,14 @@ typedef NS_ENUM(NSUInteger, FSTCurrentStatusUpdate) {
*/
@interface FSTRemoteEvent : NSObject
-+ (instancetype)
-eventWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
- targetChanges:(NSMutableDictionary<NSNumber *, FSTTargetChange *> *)targetChanges
- documentUpdates:
- (std::map<firebase::firestore::model::DocumentKey, FSTMaybeDocument *>)documentUpdates;
+- (instancetype)
+initWithSnapshotVersion:(firebase::firestore::model::SnapshotVersion)snapshotVersion
+ targetChanges:(NSMutableDictionary<NSNumber *, FSTTargetChange *> *)targetChanges
+ documentUpdates:
+ (std::map<firebase::firestore::model::DocumentKey, FSTMaybeDocument *>)documentUpdates;
/** The snapshot version this event brings us up to. */
-@property(nonatomic, strong, readonly) FSTSnapshotVersion *snapshotVersion;
+- (const firebase::firestore::model::SnapshotVersion &)snapshotVersion;
/** A map from target to changes to the target. See TargetChange. */
@property(nonatomic, strong, readonly)
@@ -194,7 +200,7 @@ eventWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
@interface FSTWatchChangeAggregator : NSObject
- (instancetype)
-initWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
+initWithSnapshotVersion:(firebase::firestore::model::SnapshotVersion)snapshotVersion
listenTargets:(NSDictionary<FSTBoxedTargetID *, FSTQueryData *> *)listenTargets
pendingTargetResponses:(NSDictionary<FSTBoxedTargetID *, NSNumber *> *)pendingTargetResponses
NS_DESIGNATED_INITIALIZER;
diff --git a/Firestore/Source/Remote/FSTRemoteEvent.mm b/Firestore/Source/Remote/FSTRemoteEvent.mm
index 30aa0d3..99cb018 100644
--- a/Firestore/Source/Remote/FSTRemoteEvent.mm
+++ b/Firestore/Source/Remote/FSTRemoteEvent.mm
@@ -19,7 +19,6 @@
#include <map>
#include <utility>
-#import "Firestore/Source/Core/FSTSnapshotVersion.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Remote/FSTWatchChange.h"
#import "Firestore/Source/Util/FSTAssert.h"
@@ -29,6 +28,7 @@
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
using firebase::firestore::model::DocumentKey;
+using firebase::firestore::model::SnapshotVersion;
NS_ASSUME_NONNULL_BEGIN
@@ -181,11 +181,12 @@ NS_ASSUME_NONNULL_BEGIN
@interface FSTTargetChange ()
@property(nonatomic, assign) FSTCurrentStatusUpdate currentStatusUpdate;
@property(nonatomic, strong, nullable) FSTTargetMapping *mapping;
-@property(nonatomic, strong) FSTSnapshotVersion *snapshotVersion;
@property(nonatomic, strong) NSData *resumeToken;
@end
-@implementation FSTTargetChange
+@implementation FSTTargetChange {
+ SnapshotVersion _snapshotVersion;
+}
- (instancetype)init {
if (self = [super init]) {
@@ -195,6 +196,17 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
+- (instancetype)initWithSnapshotVersion:(SnapshotVersion)snapshotVersion {
+ if (self = [self init]) {
+ _snapshotVersion = std::move(snapshotVersion);
+ }
+ return self;
+}
+
+- (const SnapshotVersion &)snapshotVersion {
+ return _snapshotVersion;
+}
+
+ (instancetype)changeWithDocuments:(NSArray<FSTMaybeDocument *> *)docs
currentStatusUpdate:(FSTCurrentStatusUpdate)currentStatusUpdate {
FSTUpdateMapping *mapping = [[FSTUpdateMapping alloc] init];
@@ -212,11 +224,11 @@ NS_ASSUME_NONNULL_BEGIN
}
+ (instancetype)changeWithMapping:(FSTTargetMapping *)mapping
- snapshotVersion:(FSTSnapshotVersion *)snapshotVersion
+ snapshotVersion:(SnapshotVersion)snapshotVersion
currentStatusUpdate:(FSTCurrentStatusUpdate)currentStatusUpdate {
FSTTargetChange *change = [[FSTTargetChange alloc] init];
change.mapping = mapping;
- change.snapshotVersion = snapshotVersion;
+ change->_snapshotVersion = std::move(snapshotVersion);
change.currentStatusUpdate = currentStatusUpdate;
return change;
}
@@ -248,33 +260,24 @@ NS_ASSUME_NONNULL_BEGIN
}
- (instancetype)
-initWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
+initWithSnapshotVersion:(SnapshotVersion)snapshotVersion
targetChanges:(NSMutableDictionary<FSTBoxedTargetID *, FSTTargetChange *> *)targetChanges
documentUpdates:(std::map<DocumentKey, FSTMaybeDocument *>)documentUpdates;
-@property(nonatomic, strong) FSTSnapshotVersion *snapshotVersion;
-
@end
@implementation FSTRemoteEvent {
std::map<DocumentKey, FSTMaybeDocument *> _documentUpdates;
-}
-+ (instancetype)
-eventWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
- targetChanges:(NSMutableDictionary<NSNumber *, FSTTargetChange *> *)targetChanges
- documentUpdates:(std::map<DocumentKey, FSTMaybeDocument *>)documentUpdates {
- return [[FSTRemoteEvent alloc] initWithSnapshotVersion:snapshotVersion
- targetChanges:targetChanges
- documentUpdates:std::move(documentUpdates)];
+ SnapshotVersion _snapshotVersion;
}
-- (instancetype)initWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
+- (instancetype)initWithSnapshotVersion:(SnapshotVersion)snapshotVersion
targetChanges:
(NSMutableDictionary<NSNumber *, FSTTargetChange *> *)targetChanges
documentUpdates:(std::map<DocumentKey, FSTMaybeDocument *>)documentUpdates {
self = [super init];
if (self) {
- _snapshotVersion = snapshotVersion;
+ _snapshotVersion = std::move(snapshotVersion);
_targetChanges = targetChanges;
_documentUpdates = std::move(documentUpdates);
}
@@ -330,6 +333,10 @@ eventWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
return _documentUpdates;
}
+- (const SnapshotVersion &)snapshotVersion {
+ return _snapshotVersion;
+}
+
/** Adds a document update to this remote event */
- (void)addDocumentUpdate:(FSTMaybeDocument *)document {
_documentUpdates[document.key] = document;
@@ -350,7 +357,7 @@ eventWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
// TODO(dimond): keep track of reset targets not to raise.
FSTTargetChange *targetChange =
[FSTTargetChange changeWithMapping:[[FSTResetMapping alloc] init]
- snapshotVersion:[FSTSnapshotVersion noVersion]
+ snapshotVersion:SnapshotVersion::None()
currentStatusUpdate:FSTCurrentStatusUpdateMarkNotCurrent];
_targetChanges[targetID] = targetChange;
}
@@ -361,9 +368,6 @@ eventWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
@interface FSTWatchChangeAggregator ()
-/** The snapshot version for every target change this creates. */
-@property(nonatomic, strong, readonly) FSTSnapshotVersion *snapshotVersion;
-
/** Keeps track of the current target mappings */
@property(nonatomic, strong, readonly)
NSMutableDictionary<FSTBoxedTargetID *, FSTTargetChange *> *targetChanges;
@@ -381,15 +385,17 @@ eventWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
NSMutableDictionary<FSTBoxedTargetID *, FSTExistenceFilter *> *_existenceFilters;
/** Keeps track of document to update */
std::map<DocumentKey, FSTMaybeDocument *> _documentUpdates;
+ /** The snapshot version for every target change this creates. */
+ SnapshotVersion _snapshotVersion;
}
- (instancetype)
-initWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
+initWithSnapshotVersion:(SnapshotVersion)snapshotVersion
listenTargets:(NSDictionary<FSTBoxedTargetID *, FSTQueryData *> *)listenTargets
pendingTargetResponses:(NSDictionary<FSTBoxedTargetID *, NSNumber *> *)pendingTargetResponses {
self = [super init];
if (self) {
- _snapshotVersion = snapshotVersion;
+ _snapshotVersion = std::move(snapshotVersion);
_frozen = NO;
_targetChanges = [NSMutableDictionary dictionary];
@@ -408,8 +414,7 @@ initWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
- (FSTTargetChange *)targetChangeForTargetID:(FSTBoxedTargetID *)targetID {
FSTTargetChange *change = self.targetChanges[targetID];
if (!change) {
- change = [[FSTTargetChange alloc] init];
- change.snapshotVersion = self.snapshotVersion;
+ change = [[FSTTargetChange alloc] initWithSnapshotVersion:_snapshotVersion];
self.targetChanges[targetID] = change;
}
return change;
@@ -559,9 +564,9 @@ initWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion
// Mark this aggregator as frozen so no further modifications are made.
self.frozen = YES;
- return [FSTRemoteEvent eventWithSnapshotVersion:self.snapshotVersion
- targetChanges:targetChanges
- documentUpdates:_documentUpdates];
+ return [[FSTRemoteEvent alloc] initWithSnapshotVersion:_snapshotVersion
+ targetChanges:targetChanges
+ documentUpdates:_documentUpdates];
}
@end
diff --git a/Firestore/Source/Remote/FSTRemoteStore.mm b/Firestore/Source/Remote/FSTRemoteStore.mm
index 39d285a..4dacc8e 100644
--- a/Firestore/Source/Remote/FSTRemoteStore.mm
+++ b/Firestore/Source/Remote/FSTRemoteStore.mm
@@ -19,7 +19,6 @@
#include <cinttypes>
#import "Firestore/Source/Core/FSTQuery.h"
-#import "Firestore/Source/Core/FSTSnapshotVersion.h"
#import "Firestore/Source/Core/FSTTransaction.h"
#import "Firestore/Source/Local/FSTLocalStore.h"
#import "Firestore/Source/Local/FSTQueryData.h"
@@ -37,11 +36,13 @@
#include "Firestore/core/src/firebase/firestore/auth/user.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
namespace util = firebase::firestore::util;
using firebase::firestore::auth::User;
using firebase::firestore::model::DocumentKey;
+using firebase::firestore::model::SnapshotVersion;
NS_ASSUME_NONNULL_BEGIN
@@ -299,7 +300,7 @@ static const int kMaxPendingWrites = 10;
}
- (void)watchStreamDidChange:(FSTWatchChange *)change
- snapshotVersion:(FSTSnapshotVersion *)snapshotVersion {
+ snapshotVersion:(const SnapshotVersion &)snapshotVersion {
// Mark the connection as Online because we got a message from the server.
[self.onlineStateTracker updateState:FSTOnlineStateOnline];
@@ -315,10 +316,8 @@ static const int kMaxPendingWrites = 10;
// older than a previous snapshot we've processed (can happen after we resume a target
// using a resume token).
[self.accumulatedChanges addObject:change];
- FSTAssert(snapshotVersion, @"snapshotVersion must not be nil.");
- if ([snapshotVersion isEqual:[FSTSnapshotVersion noVersion]] ||
- [snapshotVersion compare:[self.localStore lastRemoteSnapshotVersion]] ==
- NSOrderedAscending) {
+ if (snapshotVersion == SnapshotVersion::None() ||
+ snapshotVersion < SnapshotVersion{[self.localStore lastRemoteSnapshotVersion]}) {
return;
}
@@ -354,7 +353,7 @@ static const int kMaxPendingWrites = 10;
* on to the SyncEngine.
*/
- (void)processBatchedWatchChanges:(NSArray<FSTWatchChange *> *)changes
- snapshotVersion:(FSTSnapshotVersion *)snapshotVersion {
+ snapshotVersion:(const SnapshotVersion &)snapshotVersion {
FSTWatchChangeAggregator *aggregator =
[[FSTWatchChangeAggregator alloc] initWithSnapshotVersion:snapshotVersion
listenTargets:self.listenTargets
@@ -566,7 +565,7 @@ static const int kMaxPendingWrites = 10;
}
/** Handles a successful StreamingWriteResponse from the server that contains a mutation result. */
-- (void)writeStreamDidReceiveResponseWithVersion:(FSTSnapshotVersion *)commitVersion
+- (void)writeStreamDidReceiveResponseWithVersion:(const SnapshotVersion &)commitVersion
mutationResults:(NSArray<FSTMutationResult *> *)results {
// This is a response to a write containing mutations and should be correlated to the first
// pending write.
diff --git a/Firestore/Source/Remote/FSTSerializerBeta.h b/Firestore/Source/Remote/FSTSerializerBeta.h
index d96dbeb..d1371fa 100644
--- a/Firestore/Source/Remote/FSTSerializerBeta.h
+++ b/Firestore/Source/Remote/FSTSerializerBeta.h
@@ -16,8 +16,10 @@
#import <Foundation/Foundation.h>
+#include "Firestore/core/include/firebase/firestore/timestamp.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
@class FSTFieldValue;
@class FSTMaybeDocument;
@@ -27,8 +29,6 @@
@class FSTObjectValue;
@class FSTQuery;
@class FSTQueryData;
-@class FSTSnapshotVersion;
-@class FIRTimestamp;
@class FSTWatchChange;
@class GCFSBatchGetDocumentsResponse;
@@ -61,11 +61,11 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithDatabaseID:(const firebase::firestore::model::DatabaseId *)databaseID
NS_DESIGNATED_INITIALIZER;
-- (GPBTimestamp *)encodedTimestamp:(FIRTimestamp *)timestamp;
-- (FIRTimestamp *)decodedTimestamp:(GPBTimestamp *)timestamp;
+- (GPBTimestamp *)encodedTimestamp:(const firebase::Timestamp &)timestamp;
+- (firebase::Timestamp)decodedTimestamp:(GPBTimestamp *)timestamp;
-- (GPBTimestamp *)encodedVersion:(FSTSnapshotVersion *)version;
-- (FSTSnapshotVersion *)decodedVersion:(GPBTimestamp *)version;
+- (GPBTimestamp *)encodedVersion:(const firebase::firestore::model::SnapshotVersion &)version;
+- (firebase::firestore::model::SnapshotVersion)decodedVersion:(GPBTimestamp *)version;
/** Returns the database ID, such as `projects/{project id}/databases/{database_id}`. */
- (NSString *)encodedDatabaseID;
@@ -93,7 +93,8 @@ NS_ASSUME_NONNULL_BEGIN
- (FSTQuery *)decodedQueryFromQueryTarget:(GCFSTarget_QueryTarget *)target;
- (FSTWatchChange *)decodedWatchChange:(GCFSListenResponse *)watchChange;
-- (FSTSnapshotVersion *)versionFromListenResponse:(GCFSListenResponse *)watchChange;
+- (firebase::firestore::model::SnapshotVersion)versionFromListenResponse:
+ (GCFSListenResponse *)watchChange;
- (GCFSDocument *)encodedDocumentWithFields:(FSTObjectValue *)objectValue
key:(const firebase::firestore::model::DocumentKey &)key;
diff --git a/Firestore/Source/Remote/FSTSerializerBeta.mm b/Firestore/Source/Remote/FSTSerializerBeta.mm
index 5cbfecc..782e54c 100644
--- a/Firestore/Source/Remote/FSTSerializerBeta.mm
+++ b/Firestore/Source/Remote/FSTSerializerBeta.mm
@@ -33,9 +33,7 @@
#import "FIRFirestoreErrors.h"
#import "FIRGeoPoint.h"
-#import "FIRTimestamp.h"
#import "Firestore/Source/Core/FSTQuery.h"
-#import "Firestore/Source/Core/FSTSnapshotVersion.h"
#import "Firestore/Source/Local/FSTQueryData.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Model/FSTFieldValue.h"
@@ -55,8 +53,10 @@
#include "Firestore/core/src/firebase/firestore/model/transform_operations.h"
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
#include "absl/memory/memory.h"
+#include "absl/types/optional.h"
namespace util = firebase::firestore::util;
+using firebase::Timestamp;
using firebase::firestore::model::ArrayTransform;
using firebase::firestore::model::DatabaseId;
using firebase::firestore::model::DocumentKey;
@@ -86,25 +86,25 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-#pragma mark - FSTSnapshotVersion <=> GPBTimestamp
+#pragma mark - SnapshotVersion <=> GPBTimestamp
-- (GPBTimestamp *)encodedTimestamp:(FIRTimestamp *)timestamp {
+- (GPBTimestamp *)encodedTimestamp:(const Timestamp &)timestamp {
GPBTimestamp *result = [GPBTimestamp message];
- result.seconds = timestamp.seconds;
- result.nanos = timestamp.nanoseconds;
+ result.seconds = timestamp.seconds();
+ result.nanos = timestamp.nanoseconds();
return result;
}
-- (FIRTimestamp *)decodedTimestamp:(GPBTimestamp *)timestamp {
- return [[FIRTimestamp alloc] initWithSeconds:timestamp.seconds nanoseconds:timestamp.nanos];
+- (Timestamp)decodedTimestamp:(GPBTimestamp *)timestamp {
+ return Timestamp{timestamp.seconds, timestamp.nanos};
}
-- (GPBTimestamp *)encodedVersion:(FSTSnapshotVersion *)version {
- return [self encodedTimestamp:version.timestamp];
+- (GPBTimestamp *)encodedVersion:(const SnapshotVersion &)version {
+ return [self encodedTimestamp:version.timestamp()];
}
-- (FSTSnapshotVersion *)decodedVersion:(GPBTimestamp *)version {
- return [FSTSnapshotVersion versionWithTimestamp:[self decodedTimestamp:version]];
+- (SnapshotVersion)decodedVersion:(GPBTimestamp *)version {
+ return SnapshotVersion{[self decodedTimestamp:version]};
}
#pragma mark - FIRGeoPoint <=> GTPLatLng
@@ -206,8 +206,8 @@ NS_ASSUME_NONNULL_BEGIN
return [self encodedString:[fieldValue value]];
} else if (fieldClass == [FSTTimestampValue class]) {
- return [self encodedTimestampValue:[fieldValue value]];
-
+ FIRTimestamp *value = static_cast<FIRTimestamp *>([fieldValue value]);
+ return [self encodedTimestampValue:Timestamp{value.seconds, value.nanoseconds}];
} else if (fieldClass == [FSTGeoPointValue class]) {
return [self encodedGeoPointValue:[fieldValue value]];
@@ -250,8 +250,12 @@ NS_ASSUME_NONNULL_BEGIN
case GCFSValue_ValueType_OneOfCase_StringValue:
return [FSTStringValue stringValue:valueProto.stringValue];
- case GCFSValue_ValueType_OneOfCase_TimestampValue:
- return [FSTTimestampValue timestampValue:[self decodedTimestamp:valueProto.timestampValue]];
+ case GCFSValue_ValueType_OneOfCase_TimestampValue: {
+ Timestamp value = [self decodedTimestamp:valueProto.timestampValue];
+ return [FSTTimestampValue
+ timestampValue:[FIRTimestamp timestampWithSeconds:value.seconds()
+ nanoseconds:value.nanoseconds()]];
+ }
case GCFSValue_ValueType_OneOfCase_GeoPointValue:
return [FSTGeoPointValue geoPointValue:[self decodedGeoPoint:valueProto.geoPointValue]];
@@ -303,7 +307,7 @@ NS_ASSUME_NONNULL_BEGIN
return result;
}
-- (GCFSValue *)encodedTimestampValue:(FIRTimestamp *)value {
+- (GCFSValue *)encodedTimestampValue:(const Timestamp &)value {
GCFSValue *result = [GCFSValue message];
result.timestampValue = [self encodedTimestamp:value];
return result;
@@ -429,8 +433,8 @@ NS_ASSUME_NONNULL_BEGIN
FSTAssert(!!response.found, @"Tried to deserialize a found document from a deleted document.");
const DocumentKey key = [self decodedDocumentKey:response.found.name];
FSTObjectValue *value = [self decodedFields:response.found.fields];
- FSTSnapshotVersion *version = [self decodedVersion:response.found.updateTime];
- FSTAssert(![version isEqual:[FSTSnapshotVersion noVersion]],
+ SnapshotVersion version = [self decodedVersion:response.found.updateTime];
+ FSTAssert(version != SnapshotVersion::None(),
@"Got a document response with no snapshot version");
return [FSTDocument documentWithData:value key:key version:version hasLocalMutations:NO];
@@ -439,8 +443,8 @@ NS_ASSUME_NONNULL_BEGIN
- (FSTDeletedDocument *)decodedDeletedDocument:(GCFSBatchGetDocumentsResponse *)response {
FSTAssert(!!response.missing, @"Tried to deserialize a deleted document from a found document.");
const DocumentKey key = [self decodedDocumentKey:response.missing];
- FSTSnapshotVersion *version = [self decodedVersion:response.readTime];
- FSTAssert(![version isEqual:[FSTSnapshotVersion noVersion]],
+ SnapshotVersion version = [self decodedVersion:response.readTime];
+ FSTAssert(version != SnapshotVersion::None(),
@"Got a no document response with no snapshot version");
return [FSTDeletedDocument documentWithKey:key version:version];
}
@@ -668,8 +672,10 @@ NS_ASSUME_NONNULL_BEGIN
- (FSTMutationResult *)decodedMutationResult:(GCFSWriteResult *)mutation {
// NOTE: Deletes don't have an updateTime.
- FSTSnapshotVersion *_Nullable version =
- mutation.updateTime ? [self decodedVersion:mutation.updateTime] : nil;
+ absl::optional<SnapshotVersion> version;
+ if (mutation.updateTime) {
+ version = [self decodedVersion:mutation.updateTime];
+ }
NSMutableArray *_Nullable transformResults = nil;
if (mutation.transformResultsArray.count > 0) {
transformResults = [NSMutableArray array];
@@ -677,7 +683,8 @@ NS_ASSUME_NONNULL_BEGIN
[transformResults addObject:[self decodedFieldValue:result]];
}
}
- return [[FSTMutationResult alloc] initWithVersion:version transformResults:transformResults];
+ return [[FSTMutationResult alloc]
+ initWithVersion:(version ? version.value() : nil)transformResults:transformResults];
}
#pragma mark - FSTQueryData => GCFSTarget proto
@@ -1071,15 +1078,15 @@ NS_ASSUME_NONNULL_BEGIN
}
}
-- (FSTSnapshotVersion *)versionFromListenResponse:(GCFSListenResponse *)watchChange {
+- (SnapshotVersion)versionFromListenResponse:(GCFSListenResponse *)watchChange {
// We have only reached a consistent snapshot for the entire stream if there is a read_time set
// and it applies to all targets (i.e. the list of targets is empty). The backend is guaranteed to
// send such responses.
if (watchChange.responseTypeOneOfCase != GCFSListenResponse_ResponseType_OneOfCase_TargetChange) {
- return [FSTSnapshotVersion noVersion];
+ return SnapshotVersion::None();
}
if (watchChange.targetChange.targetIdsArray.count != 0) {
- return [FSTSnapshotVersion noVersion];
+ return SnapshotVersion::None();
}
return [self decodedVersion:watchChange.targetChange.readTime];
}
@@ -1135,9 +1142,8 @@ NS_ASSUME_NONNULL_BEGIN
- (FSTDocumentWatchChange *)decodedDocumentChange:(GCFSDocumentChange *)change {
FSTObjectValue *value = [self decodedFields:change.document.fields];
const DocumentKey key = [self decodedDocumentKey:change.document.name];
- FSTSnapshotVersion *version = [self decodedVersion:change.document.updateTime];
- FSTAssert(![version isEqual:[FSTSnapshotVersion noVersion]],
- @"Got a document change with no snapshot version");
+ SnapshotVersion version = [self decodedVersion:change.document.updateTime];
+ FSTAssert(version != SnapshotVersion::None(), @"Got a document change with no snapshot version");
FSTMaybeDocument *document =
[FSTDocument documentWithData:value key:key version:version hasLocalMutations:NO];
@@ -1152,8 +1158,8 @@ NS_ASSUME_NONNULL_BEGIN
- (FSTDocumentWatchChange *)decodedDocumentDelete:(GCFSDocumentDelete *)change {
const DocumentKey key = [self decodedDocumentKey:change.document];
- // Note that version might be unset in which case we use [FSTSnapshotVersion noVersion]
- FSTSnapshotVersion *version = [self decodedVersion:change.readTime];
+ // Note that version might be unset in which case we use SnapshotVersion::None()
+ SnapshotVersion version = [self decodedVersion:change.readTime];
FSTMaybeDocument *document = [FSTDeletedDocument documentWithKey:key version:version];
NSArray<NSNumber *> *removedTargetIds = [self decodedIntegerArray:change.removedTargetIdsArray];
diff --git a/Firestore/Source/Remote/FSTStream.h b/Firestore/Source/Remote/FSTStream.h
index fba79d2..3bd8549 100644
--- a/Firestore/Source/Remote/FSTStream.h
+++ b/Firestore/Source/Remote/FSTStream.h
@@ -21,13 +21,13 @@
#include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h"
#include "Firestore/core/src/firebase/firestore/core/database_info.h"
+#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
@class FSTDispatchQueue;
@class FSTMutation;
@class FSTMutationResult;
@class FSTQueryData;
@class FSTSerializerBeta;
-@class FSTSnapshotVersion;
@class FSTWatchChange;
@class FSTWatchStream;
@class FSTWriteStream;
@@ -179,7 +179,7 @@ NS_ASSUME_NONNULL_BEGIN
* WatchChange responses sent back by the server.
*/
- (void)watchStreamDidChange:(FSTWatchChange *)change
- snapshotVersion:(FSTSnapshotVersion *)snapshotVersion;
+ snapshotVersion:(const firebase::firestore::model::SnapshotVersion &)snapshotVersion;
/**
* Called by the FSTWatchStream when the underlying streaming RPC is interrupted for whatever
@@ -250,7 +250,8 @@ NS_ASSUME_NONNULL_BEGIN
* Called by the FSTWriteStream upon receiving a StreamingWriteResponse from the server that
* contains mutation results.
*/
-- (void)writeStreamDidReceiveResponseWithVersion:(FSTSnapshotVersion *)commitVersion
+- (void)writeStreamDidReceiveResponseWithVersion:
+ (const firebase::firestore::model::SnapshotVersion &)commitVersion
mutationResults:(NSArray<FSTMutationResult *> *)results;
/**
diff --git a/Firestore/Source/Remote/FSTStream.mm b/Firestore/Source/Remote/FSTStream.mm
index a96feae..f4ec675 100644
--- a/Firestore/Source/Remote/FSTStream.mm
+++ b/Firestore/Source/Remote/FSTStream.mm
@@ -36,6 +36,7 @@
#include "Firestore/core/src/firebase/firestore/auth/token.h"
#include "Firestore/core/src/firebase/firestore/core/database_info.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
+#include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
#include "Firestore/core/src/firebase/firestore/util/error_apple.h"
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
@@ -44,6 +45,7 @@ using firebase::firestore::auth::CredentialsProvider;
using firebase::firestore::auth::Token;
using firebase::firestore::core::DatabaseInfo;
using firebase::firestore::model::DatabaseId;
+using firebase::firestore::model::SnapshotVersion;
/**
* Initial backoff time in seconds after an error.
@@ -691,7 +693,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
[self.backoff reset];
FSTWatchChange *change = [_serializer decodedWatchChange:proto];
- FSTSnapshotVersion *snap = [_serializer versionFromListenResponse:proto];
+ SnapshotVersion snap = [_serializer versionFromListenResponse:proto];
[self.delegate watchStreamDidChange:change snapshotVersion:snap];
}
@@ -807,7 +809,7 @@ static const NSTimeInterval kIdleTimeout = 60.0;
// might be causing an error we want to back off from.
[self.backoff reset];
- FSTSnapshotVersion *commitVersion = [_serializer decodedVersion:response.commitTime];
+ SnapshotVersion commitVersion = [_serializer decodedVersion:response.commitTime];
NSMutableArray<GCFSWriteResult *> *protos = response.writeResultsArray;
NSMutableArray<FSTMutationResult *> *results = [NSMutableArray arrayWithCapacity:protos.count];
for (GCFSWriteResult *proto in protos) {
diff --git a/Firestore/Source/Remote/FSTWatchChange.h b/Firestore/Source/Remote/FSTWatchChange.h
index 8f730de..ed80e1a 100644
--- a/Firestore/Source/Remote/FSTWatchChange.h
+++ b/Firestore/Source/Remote/FSTWatchChange.h
@@ -22,7 +22,6 @@
@class FSTExistenceFilter;
@class FSTMaybeDocument;
-@class FSTSnapshotVersion;
NS_ASSUME_NONNULL_BEGIN