Search in sources :

Example 1 with DirectionalIndexByteEncoder

use of com.google.firebase.firestore.index.DirectionalIndexByteEncoder 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);
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex) DirectionalIndexByteEncoder(com.google.firebase.firestore.index.DirectionalIndexByteEncoder) ArrayList(java.util.ArrayList) Value(com.google.firestore.v1.Value) DirectionalIndexByteEncoder(com.google.firebase.firestore.index.DirectionalIndexByteEncoder) IndexByteEncoder(com.google.firebase.firestore.index.IndexByteEncoder) Nullable(androidx.annotation.Nullable)

Example 2 with DirectionalIndexByteEncoder

use of com.google.firebase.firestore.index.DirectionalIndexByteEncoder 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();
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex) DirectionalIndexByteEncoder(com.google.firebase.firestore.index.DirectionalIndexByteEncoder) Value(com.google.firestore.v1.Value) DirectionalIndexByteEncoder(com.google.firebase.firestore.index.DirectionalIndexByteEncoder) IndexByteEncoder(com.google.firebase.firestore.index.IndexByteEncoder) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)2 DirectionalIndexByteEncoder (com.google.firebase.firestore.index.DirectionalIndexByteEncoder)2 IndexByteEncoder (com.google.firebase.firestore.index.IndexByteEncoder)2 FieldIndex (com.google.firebase.firestore.model.FieldIndex)2 Value (com.google.firestore.v1.Value)2 ArrayList (java.util.ArrayList)1