use of com.google.firebase.firestore.index.IndexByteEncoder 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.firebase.firestore.index.IndexByteEncoder in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method encodeDirectionalElements.
/**
* Returns the byte encoded form of the directional values in the field index. Returns {@code
* null} if the document does not have all fields specified in the index.
*/
@Nullable
private byte[] encodeDirectionalElements(FieldIndex fieldIndex, Document document) {
IndexByteEncoder encoder = new IndexByteEncoder();
for (FieldIndex.Segment segment : fieldIndex.getDirectionalSegments()) {
Value field = document.getField(segment.getFieldPath());
if (field == null) {
return null;
}
DirectionalIndexByteEncoder directionalEncoder = encoder.forKind(segment.getKind());
FirestoreIndexValueWriter.INSTANCE.writeIndexValue(field, directionalEncoder);
}
return encoder.getEncodedBytes();
}
use of com.google.firebase.firestore.index.IndexByteEncoder in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method expandIndexValues.
/**
* Creates a separate encoder for each element of an array.
*
* <p>The method appends each value to all existing encoders (e.g. filter("a", "==",
* "a1").filter("b", "in", ["b1", "b2"]) becomes ["a1,b1", "a1,b2"]). A list of new encoders is
* returned.
*/
private List<IndexByteEncoder> expandIndexValues(List<IndexByteEncoder> encoders, FieldIndex.Segment segment, Value value) {
List<IndexByteEncoder> prefixes = new ArrayList<>(encoders);
List<IndexByteEncoder> results = new ArrayList<>();
for (Value arrayElement : value.getArrayValue().getValuesList()) {
for (IndexByteEncoder prefix : prefixes) {
IndexByteEncoder clonedEncoder = new IndexByteEncoder();
clonedEncoder.seed(prefix.getEncodedBytes());
FirestoreIndexValueWriter.INSTANCE.writeIndexValue(arrayElement, clonedEncoder.forKind(segment.getKind()));
results.add(clonedEncoder);
}
}
return results;
}
use of com.google.firebase.firestore.index.IndexByteEncoder in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method encodeSingleElement.
/**
* Encodes a single value to the ascending index format.
*/
private byte[] encodeSingleElement(Value value) {
IndexByteEncoder encoder = new IndexByteEncoder();
FirestoreIndexValueWriter.INSTANCE.writeIndexValue(value, encoder.forKind(FieldIndex.Segment.Kind.ASCENDING));
return encoder.getEncodedBytes();
}
Aggregations