Skip to content

Add JSON deserializer #2331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 15, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public interface BundleCache {
* under the given id.
*/
@Nullable
Bundle getBundleMetadata(String bundleId);
BundleMetadata getBundleMetadata(String bundleId);

/** Saves the metadata from a bundle into local storage, using its id as the persistent key. */
void saveBundleMetadata(Bundle metadata);
void saveBundleMetadata(BundleMetadata metadata);

/**
* Gets a saved NamedQuery for the given query name. Returns {@code null} if no queries are found
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.firestore.local;

import com.google.firebase.firestore.model.SnapshotVersion;

/** Represents a Firestore bundle saved by the SDK in its local storage. */
/* package */ class BundleMetadata {
private final String bundleId;
private final int version;
private final SnapshotVersion createTime;

public BundleMetadata(String bundleId, int version, SnapshotVersion createTime) {
this.bundleId = bundleId;
this.version = version;
this.createTime = createTime;
}

/**
* Returns the ID of the bundle. It is used together with `createTime` to determine if a bundle
* has been loaded by the SDK.
*/
public String getBundleId() {
return bundleId;
}

/** Returns the schema version of the bundle. */
public int getVersion() {
return version;
}

/**
* Returns the snapshot version of the bundle if created by the Server SDKs, or else
* SnapshotVersion.MIN.
*/
public SnapshotVersion getCreateTime() {
return createTime;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

BundleMetadata that = (BundleMetadata) o;

if (version != that.version) return false;
if (!bundleId.equals(that.bundleId)) return false;
return createTime.equals(that.createTime);
}

@Override
public int hashCode() {
int result = bundleId.hashCode();
result = 31 * result + version;
result = 31 * result + createTime.hashCode();
return result;
}
}
Loading