use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method encodeValues.
/**
* Encodes the given field values according to the specification in {@code target}. For IN
* queries, a list of possible values is returned.
*/
@Nullable
private Object[] encodeValues(FieldIndex fieldIndex, Target target, @Nullable Collection<Value> values) {
if (values == null)
return null;
List<IndexByteEncoder> encoders = new ArrayList<>();
encoders.add(new IndexByteEncoder());
Iterator<Value> position = values.iterator();
for (FieldIndex.Segment segment : fieldIndex.getDirectionalSegments()) {
Value value = position.next();
for (IndexByteEncoder encoder : encoders) {
if (isInFilter(target, segment.getFieldPath()) && isArray(value)) {
encoders = expandIndexValues(encoders, segment, value);
} else {
DirectionalIndexByteEncoder directionalEncoder = encoder.forKind(segment.getKind());
FirestoreIndexValueWriter.INSTANCE.writeIndexValue(value, directionalEncoder);
}
}
}
return getEncodedBytes(encoders);
}
use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodesFirstLevelKeyQueries.
@Test
public void testEncodesFirstLevelKeyQueries() {
Query q = Query.atPath(ResourcePath.fromString("docs/1"));
Target actual = serializer.encodeTarget(new TargetData(q.toTarget(), 1, 2, QueryPurpose.LISTEN));
DocumentsTarget.Builder docs = DocumentsTarget.newBuilder().addDocuments("projects/p/databases/d/documents/docs/1");
Target expected = Target.newBuilder().setDocuments(docs).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
assertEquals(expected, actual);
assertEquals(serializer.decodeDocumentsTarget(serializer.encodeDocumentsTarget(q.toTarget())), q.toTarget());
}
use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodesFirstLevelAncestorQueries.
@Test
public void testEncodesFirstLevelAncestorQueries() {
Query q = Query.atPath(ResourcePath.fromString("messages"));
Target actual = serializer.encodeTarget(wrapTargetData(q));
StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("messages")).addOrderBy(defaultKeyOrder());
QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
assertEquals(expected, actual);
assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodesSortOrders.
@Test
public void testEncodesSortOrders() {
Query q = Query.atPath(ResourcePath.fromString("docs")).orderBy(orderBy("prop"));
Target actual = serializer.encodeTarget(wrapTargetData(q));
StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).addOrderBy(Order.newBuilder().setDirection(Direction.ASCENDING).setField(FieldReference.newBuilder().setFieldPath("prop"))).addOrderBy(defaultKeyOrder());
QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
assertEquals(expected, actual);
assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodesResumeTokens.
@Test
public void testEncodesResumeTokens() {
Query q = Query.atPath(ResourcePath.fromString("docs"));
TargetData targetData = new TargetData(q.toTarget(), 1, 2, QueryPurpose.LISTEN).withResumeToken(TestUtil.resumeToken(1000), SnapshotVersion.NONE);
Target actual = serializer.encodeTarget(targetData);
StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).addOrderBy(defaultKeyOrder());
QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(TestUtil.resumeToken(1000)).build();
assertEquals(expected, actual);
assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Aggregations