269 lines
13 KiB
Java
269 lines
13 KiB
Java
|
package com.google.firebase.firestore.local;
|
||
|
|
||
|
import com.google.firebase.Timestamp;
|
||
|
import com.google.firebase.firestore.model.Document;
|
||
|
import com.google.firebase.firestore.model.DocumentKey;
|
||
|
import com.google.firebase.firestore.model.FieldIndex;
|
||
|
import com.google.firebase.firestore.model.FieldPath;
|
||
|
import com.google.firebase.firestore.model.MutableDocument;
|
||
|
import com.google.firebase.firestore.model.ObjectValue;
|
||
|
import com.google.firebase.firestore.model.SnapshotVersion;
|
||
|
import com.google.firebase.firestore.model.mutation.Mutation;
|
||
|
import com.google.firebase.firestore.model.mutation.MutationBatch;
|
||
|
import com.google.firebase.firestore.proto.MaybeDocument;
|
||
|
import com.google.firebase.firestore.proto.NoDocument;
|
||
|
import com.google.firebase.firestore.proto.Target;
|
||
|
import com.google.firebase.firestore.proto.UnknownDocument;
|
||
|
import com.google.firebase.firestore.proto.WriteBatch;
|
||
|
import com.google.firebase.firestore.remote.RemoteSerializer;
|
||
|
import com.google.firebase.firestore.util.Assert;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Collections;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.List;
|
||
|
import o.AQX;
|
||
|
import o.ECo;
|
||
|
import o.JsL;
|
||
|
import o.QwV;
|
||
|
import o.SPR;
|
||
|
import o.veo;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class LocalSerializer {
|
||
|
private final RemoteSerializer rpcSerializer;
|
||
|
|
||
|
public LocalSerializer(RemoteSerializer remoteSerializer) {
|
||
|
this.rpcSerializer = remoteSerializer;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final MaybeDocument encodeMaybeDocument(Document document) {
|
||
|
MaybeDocument.Builder newBuilder = MaybeDocument.newBuilder();
|
||
|
if (document.isNoDocument()) {
|
||
|
newBuilder.setNoDocument(encodeNoDocument(document));
|
||
|
} else if (document.isFoundDocument()) {
|
||
|
newBuilder.setDocument(encodeDocument(document));
|
||
|
} else if (document.isUnknownDocument()) {
|
||
|
newBuilder.setUnknownDocument(encodeUnknownDocument(document));
|
||
|
} else {
|
||
|
throw Assert.fail("Cannot encode invalid document %s", document);
|
||
|
}
|
||
|
newBuilder.setHasCommittedMutations(document.hasCommittedMutations());
|
||
|
return newBuilder.build();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final MutableDocument decodeMaybeDocument(MaybeDocument maybeDocument) {
|
||
|
int i = AnonymousClass1.$SwitchMap$com$google$firebase$firestore$proto$MaybeDocument$DocumentTypeCase[maybeDocument.getDocumentTypeCase().ordinal()];
|
||
|
if (i == 1) {
|
||
|
return decodeDocument(maybeDocument.getDocument(), maybeDocument.getHasCommittedMutations());
|
||
|
}
|
||
|
if (i == 2) {
|
||
|
return decodeNoDocument(maybeDocument.getNoDocument(), maybeDocument.getHasCommittedMutations());
|
||
|
}
|
||
|
if (i == 3) {
|
||
|
return decodeUnknownDocument(maybeDocument.getUnknownDocument());
|
||
|
}
|
||
|
throw Assert.fail("Unknown MaybeDocument %s", maybeDocument);
|
||
|
}
|
||
|
|
||
|
private SPR encodeDocument(Document document) {
|
||
|
SPR.IeS e = SPR.e();
|
||
|
e.d(this.rpcSerializer.encodeKey(document.getKey()));
|
||
|
e.c(document.getData().getFieldsMap());
|
||
|
e.e(this.rpcSerializer.encodeTimestamp(document.getVersion().getTimestamp()));
|
||
|
return e.build();
|
||
|
}
|
||
|
|
||
|
private NoDocument encodeNoDocument(Document document) {
|
||
|
NoDocument.Builder newBuilder = NoDocument.newBuilder();
|
||
|
newBuilder.setName(this.rpcSerializer.encodeKey(document.getKey()));
|
||
|
newBuilder.setReadTime(this.rpcSerializer.encodeTimestamp(document.getVersion().getTimestamp()));
|
||
|
return newBuilder.build();
|
||
|
}
|
||
|
|
||
|
private MutableDocument decodeNoDocument(NoDocument noDocument, boolean z) {
|
||
|
MutableDocument newNoDocument = MutableDocument.newNoDocument(this.rpcSerializer.decodeKey(noDocument.getName()), this.rpcSerializer.decodeVersion(noDocument.getReadTime()));
|
||
|
return z ? newNoDocument.setHasCommittedMutations() : newNoDocument;
|
||
|
}
|
||
|
|
||
|
private UnknownDocument encodeUnknownDocument(Document document) {
|
||
|
UnknownDocument.Builder newBuilder = UnknownDocument.newBuilder();
|
||
|
newBuilder.setName(this.rpcSerializer.encodeKey(document.getKey()));
|
||
|
newBuilder.setVersion(this.rpcSerializer.encodeTimestamp(document.getVersion().getTimestamp()));
|
||
|
return newBuilder.build();
|
||
|
}
|
||
|
|
||
|
private MutableDocument decodeUnknownDocument(UnknownDocument unknownDocument) {
|
||
|
return MutableDocument.newUnknownDocument(this.rpcSerializer.decodeKey(unknownDocument.getName()), this.rpcSerializer.decodeVersion(unknownDocument.getVersion()));
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final WriteBatch encodeMutationBatch(MutationBatch mutationBatch) {
|
||
|
WriteBatch.Builder newBuilder = WriteBatch.newBuilder();
|
||
|
newBuilder.setBatchId(mutationBatch.getBatchId());
|
||
|
newBuilder.setLocalWriteTime(this.rpcSerializer.encodeTimestamp(mutationBatch.getLocalWriteTime()));
|
||
|
Iterator<Mutation> it = mutationBatch.getBaseMutations().iterator();
|
||
|
while (it.hasNext()) {
|
||
|
newBuilder.addBaseWrites(this.rpcSerializer.encodeMutation(it.next()));
|
||
|
}
|
||
|
Iterator<Mutation> it2 = mutationBatch.getMutations().iterator();
|
||
|
while (it2.hasNext()) {
|
||
|
newBuilder.addWrites(this.rpcSerializer.encodeMutation(it2.next()));
|
||
|
}
|
||
|
return newBuilder.build();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final MutationBatch decodeMutationBatch(WriteBatch writeBatch) {
|
||
|
veo a;
|
||
|
int batchId = writeBatch.getBatchId();
|
||
|
Timestamp decodeTimestamp = this.rpcSerializer.decodeTimestamp(writeBatch.getLocalWriteTime());
|
||
|
int baseWritesCount = writeBatch.getBaseWritesCount();
|
||
|
ArrayList arrayList = new ArrayList(baseWritesCount);
|
||
|
for (int i = 0; i < baseWritesCount; i++) {
|
||
|
arrayList.add(this.rpcSerializer.decodeMutation(writeBatch.getBaseWrites(i)));
|
||
|
}
|
||
|
ArrayList arrayList2 = new ArrayList(writeBatch.getWritesCount());
|
||
|
int i2 = 0;
|
||
|
while (i2 < writeBatch.getWritesCount()) {
|
||
|
JsL writes = writeBatch.getWrites(i2);
|
||
|
int i3 = i2 + 1;
|
||
|
if (i3 < writeBatch.getWritesCount() && writeBatch.getWrites(i3).operationCase_ == 6) {
|
||
|
Assert.hardAssert(writeBatch.getWrites(i2).operationCase_ == 1, "TransformMutation should be preceded by a patch or set mutation", new Object[0]);
|
||
|
JsL.LWm d = JsL.d(writes);
|
||
|
JsL writes2 = writeBatch.getWrites(i3);
|
||
|
if (writes2.operationCase_ == 6) {
|
||
|
a = (veo) writes2.operation_;
|
||
|
} else {
|
||
|
a = veo.a();
|
||
|
}
|
||
|
Iterator<veo.Sts> it = a.fieldTransforms_.iterator();
|
||
|
while (it.hasNext()) {
|
||
|
d.e(it.next());
|
||
|
}
|
||
|
arrayList2.add(this.rpcSerializer.decodeMutation(d.build()));
|
||
|
i2 = i3;
|
||
|
} else {
|
||
|
arrayList2.add(this.rpcSerializer.decodeMutation(writes));
|
||
|
}
|
||
|
i2++;
|
||
|
}
|
||
|
return new MutationBatch(batchId, decodeTimestamp, arrayList, arrayList2);
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final Target encodeTargetData(TargetData targetData) {
|
||
|
Assert.hardAssert(QueryPurpose.LISTEN.equals(targetData.getPurpose()), "Only queries with purpose %s may be stored, got %s", QueryPurpose.LISTEN, targetData.getPurpose());
|
||
|
Target.Builder newBuilder = Target.newBuilder();
|
||
|
newBuilder.setTargetId(targetData.getTargetId()).setLastListenSequenceNumber(targetData.getSequenceNumber()).setLastLimboFreeSnapshotVersion(this.rpcSerializer.encodeVersion(targetData.getLastLimboFreeSnapshotVersion())).setSnapshotVersion(this.rpcSerializer.encodeVersion(targetData.getSnapshotVersion())).setResumeToken(targetData.getResumeToken());
|
||
|
com.google.firebase.firestore.core.Target target = targetData.getTarget();
|
||
|
if (target.isDocumentQuery()) {
|
||
|
newBuilder.setDocuments(this.rpcSerializer.encodeDocumentsTarget(target));
|
||
|
} else {
|
||
|
newBuilder.setQuery(this.rpcSerializer.encodeQueryTarget(target));
|
||
|
}
|
||
|
return newBuilder.build();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final TargetData decodeTargetData(Target target) {
|
||
|
com.google.firebase.firestore.core.Target decodeDocumentsTarget;
|
||
|
int targetId = target.getTargetId();
|
||
|
SnapshotVersion decodeVersion = this.rpcSerializer.decodeVersion(target.getSnapshotVersion());
|
||
|
SnapshotVersion decodeVersion2 = this.rpcSerializer.decodeVersion(target.getLastLimboFreeSnapshotVersion());
|
||
|
QwV resumeToken = target.getResumeToken();
|
||
|
long lastListenSequenceNumber = target.getLastListenSequenceNumber();
|
||
|
int i = AnonymousClass1.$SwitchMap$com$google$firebase$firestore$proto$Target$TargetTypeCase[target.getTargetTypeCase().ordinal()];
|
||
|
if (i == 1) {
|
||
|
decodeDocumentsTarget = this.rpcSerializer.decodeDocumentsTarget(target.getDocuments());
|
||
|
} else if (i == 2) {
|
||
|
decodeDocumentsTarget = this.rpcSerializer.decodeQueryTarget(target.getQuery());
|
||
|
} else {
|
||
|
throw Assert.fail("Unknown targetType %d", target.getTargetTypeCase());
|
||
|
}
|
||
|
return new TargetData(decodeDocumentsTarget, targetId, lastListenSequenceNumber, QueryPurpose.LISTEN, decodeVersion, decodeVersion2, resumeToken);
|
||
|
}
|
||
|
|
||
|
/* renamed from: com.google.firebase.firestore.local.LocalSerializer$1, reason: invalid class name */
|
||
|
/* loaded from: classes2.dex */
|
||
|
static /* synthetic */ class AnonymousClass1 {
|
||
|
static final int[] $SwitchMap$com$google$firebase$firestore$proto$MaybeDocument$DocumentTypeCase;
|
||
|
static final int[] $SwitchMap$com$google$firebase$firestore$proto$Target$TargetTypeCase;
|
||
|
|
||
|
static {
|
||
|
int[] iArr = new int[Target.TargetTypeCase.values().length];
|
||
|
$SwitchMap$com$google$firebase$firestore$proto$Target$TargetTypeCase = iArr;
|
||
|
try {
|
||
|
iArr[Target.TargetTypeCase.DOCUMENTS.ordinal()] = 1;
|
||
|
} catch (NoSuchFieldError unused) {
|
||
|
}
|
||
|
try {
|
||
|
$SwitchMap$com$google$firebase$firestore$proto$Target$TargetTypeCase[Target.TargetTypeCase.QUERY.ordinal()] = 2;
|
||
|
} catch (NoSuchFieldError unused2) {
|
||
|
}
|
||
|
int[] iArr2 = new int[MaybeDocument.DocumentTypeCase.values().length];
|
||
|
$SwitchMap$com$google$firebase$firestore$proto$MaybeDocument$DocumentTypeCase = iArr2;
|
||
|
try {
|
||
|
iArr2[MaybeDocument.DocumentTypeCase.DOCUMENT.ordinal()] = 1;
|
||
|
} catch (NoSuchFieldError unused3) {
|
||
|
}
|
||
|
try {
|
||
|
$SwitchMap$com$google$firebase$firestore$proto$MaybeDocument$DocumentTypeCase[MaybeDocument.DocumentTypeCase.NO_DOCUMENT.ordinal()] = 2;
|
||
|
} catch (NoSuchFieldError unused4) {
|
||
|
}
|
||
|
try {
|
||
|
$SwitchMap$com$google$firebase$firestore$proto$MaybeDocument$DocumentTypeCase[MaybeDocument.DocumentTypeCase.UNKNOWN_DOCUMENT.ordinal()] = 3;
|
||
|
} catch (NoSuchFieldError unused5) {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final List<FieldIndex.Segment> decodeFieldIndexSegments(ECo eCo) {
|
||
|
ECo.IeS.LWm lWm;
|
||
|
FieldIndex.Segment.Kind kind;
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
for (ECo.IeS ieS : eCo.fields_) {
|
||
|
FieldPath fromServerFormat = FieldPath.fromServerFormat(ieS.fieldPath_);
|
||
|
if (ECo.IeS.Sts.b(ieS.valueModeCase_).equals(ECo.IeS.Sts.ARRAY_CONFIG)) {
|
||
|
kind = FieldIndex.Segment.Kind.CONTAINS;
|
||
|
} else {
|
||
|
if (ieS.valueModeCase_ == 2) {
|
||
|
lWm = ECo.IeS.LWm.a(((Integer) ieS.valueMode_).intValue());
|
||
|
if (lWm == null) {
|
||
|
lWm = ECo.IeS.LWm.UNRECOGNIZED;
|
||
|
}
|
||
|
} else {
|
||
|
lWm = ECo.IeS.LWm.ORDER_UNSPECIFIED;
|
||
|
}
|
||
|
if (lWm.equals(ECo.IeS.LWm.ASCENDING)) {
|
||
|
kind = FieldIndex.Segment.Kind.ASCENDING;
|
||
|
} else {
|
||
|
kind = FieldIndex.Segment.Kind.DESCENDING;
|
||
|
}
|
||
|
}
|
||
|
arrayList.add(FieldIndex.Segment.create(fromServerFormat, kind));
|
||
|
}
|
||
|
return arrayList;
|
||
|
}
|
||
|
|
||
|
public final Mutation decodeMutation(JsL jsL) {
|
||
|
return this.rpcSerializer.decodeMutation(jsL);
|
||
|
}
|
||
|
|
||
|
public final JsL encodeMutation(Mutation mutation) {
|
||
|
return this.rpcSerializer.encodeMutation(mutation);
|
||
|
}
|
||
|
|
||
|
private MutableDocument decodeDocument(SPR spr, boolean z) {
|
||
|
DocumentKey decodeKey = this.rpcSerializer.decodeKey(spr.name_);
|
||
|
RemoteSerializer remoteSerializer = this.rpcSerializer;
|
||
|
AQX aqx = spr.updateTime_;
|
||
|
if (aqx == null) {
|
||
|
aqx = AQX.c();
|
||
|
}
|
||
|
MutableDocument newFoundDocument = MutableDocument.newFoundDocument(decodeKey, remoteSerializer.decodeVersion(aqx), ObjectValue.fromMap(Collections.unmodifiableMap(spr.fields_)));
|
||
|
return z ? newFoundDocument.setHasCommittedMutations() : newFoundDocument;
|
||
|
}
|
||
|
}
|