use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.
the class LocalSerializer method encodeTargetData.
com.google.firebase.firestore.proto.Target encodeTargetData(TargetData targetData) {
hardAssert(QueryPurpose.LISTEN.equals(targetData.getPurpose()), "Only queries with purpose %s may be stored, got %s", QueryPurpose.LISTEN, targetData.getPurpose());
com.google.firebase.firestore.proto.Target.Builder result = com.google.firebase.firestore.proto.Target.newBuilder();
result.setTargetId(targetData.getTargetId()).setLastListenSequenceNumber(targetData.getSequenceNumber()).setLastLimboFreeSnapshotVersion(rpcSerializer.encodeVersion(targetData.getLastLimboFreeSnapshotVersion())).setSnapshotVersion(rpcSerializer.encodeVersion(targetData.getSnapshotVersion())).setResumeToken(targetData.getResumeToken());
Target target = targetData.getTarget();
if (target.isDocumentQuery()) {
result.setDocuments(rpcSerializer.encodeDocumentsTarget(target));
} else {
result.setQuery(rpcSerializer.encodeQueryTarget(target));
}
return result.build();
}
use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.
the class LocalSerializer method decodeTargetData.
TargetData decodeTargetData(com.google.firebase.firestore.proto.Target targetProto) {
int targetId = targetProto.getTargetId();
SnapshotVersion version = rpcSerializer.decodeVersion(targetProto.getSnapshotVersion());
SnapshotVersion lastLimboFreeSnapshotVersion = rpcSerializer.decodeVersion(targetProto.getLastLimboFreeSnapshotVersion());
ByteString resumeToken = targetProto.getResumeToken();
long sequenceNumber = targetProto.getLastListenSequenceNumber();
Target target;
switch(targetProto.getTargetTypeCase()) {
case DOCUMENTS:
target = rpcSerializer.decodeDocumentsTarget(targetProto.getDocuments());
break;
case QUERY:
target = rpcSerializer.decodeQueryTarget(targetProto.getQuery());
break;
default:
throw fail("Unknown targetType %d", targetProto.getTargetTypeCase());
}
return new TargetData(target, targetId, sequenceNumber, QueryPurpose.LISTEN, version, lastLimboFreeSnapshotVersion, resumeToken);
}
use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.
the class SQLiteIndexManagerTest method verifyResults.
private void verifyResults(Query query, String... documents) {
Target target = query.toTarget();
Iterable<DocumentKey> results = indexManager.getDocumentsMatchingTarget(target);
assertNotNull("Target cannot be served from index.", results);
List<DocumentKey> keys = Arrays.stream(documents).map(s -> key(s)).collect(Collectors.toList());
assertWithMessage("Result for %s", query).that(results).containsExactlyElementsIn(keys);
}
use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.
the class BundleCacheTestCase method testReturnsSavedLimitToFirstQueries.
@Test
public void testReturnsSavedLimitToFirstQueries() {
Target target = new Target(path("room"), /* collectionGroup= */
null, Collections.emptyList(), Collections.emptyList(), /* limit= */
1, /* startAt= */
null, /* endAt= */
null);
BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_FIRST);
NamedQuery expectedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(Timestamp.now()));
bundleCache.saveNamedQuery(expectedQuery);
NamedQuery actualQuery = bundleCache.getNamedQuery("query-1");
assertEquals(expectedQuery, actualQuery);
}
use of com.google.firebase.firestore.core.Target in project firebase-android-sdk by firebase.
the class BundleCacheTestCase method testReturnsSavedLimitToLastQueries.
@Test
public void testReturnsSavedLimitToLastQueries() {
Target target = new Target(path("room"), /* collectionGroup= */
null, Collections.emptyList(), Collections.emptyList(), /* limit= */
1, /* startAt= */
null, /* endAt= */
null);
BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_LAST);
NamedQuery expectedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(Timestamp.now()));
bundleCache.saveNamedQuery(expectedQuery);
NamedQuery actualQuery = bundleCache.getNamedQuery("query-1");
assertEquals(expectedQuery, actualQuery);
}
Aggregations