Skip to content
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

Continue Firestore Codable 3 #2229

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FirebaseFirestoreSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Pod::Spec.new do |s|
s.name = 'FirebaseFirestoreSwift'
s.version = '0.1'
s.version = '0.2.0'
s.summary = 'Google Cloud Firestore for iOS Swift Extensions'

s.description = <<-DESC
Expand Down
31 changes: 29 additions & 2 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,14 @@
DE03B2D61F2149D600A30B9C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; };
DE03B2DD1F2149D600A30B9C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
DE03B3631F215E1A00A30B9C /* CAcert.pem in Resources */ = {isa = PBXBuildFile; fileRef = DE03B3621F215E1600A30B9C /* CAcert.pem */; };
DE26C61621C15FCC00DE141A /* CodableDocumentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE26C61521C15FCC00DE141A /* CodableDocumentTests.swift */; };
DE2EF0851F3D0B6E003D0CDC /* FSTArraySortedDictionaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE2EF07E1F3D0B6E003D0CDC /* FSTArraySortedDictionaryTests.m */; };
DE2EF0861F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.m in Sources */ = {isa = PBXBuildFile; fileRef = DE2EF0801F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.m */; };
DE2EF0871F3D0B6E003D0CDC /* FSTImmutableSortedSet+Testing.m in Sources */ = {isa = PBXBuildFile; fileRef = DE2EF0821F3D0B6E003D0CDC /* FSTImmutableSortedSet+Testing.m */; };
DE2EF0881F3D0B6E003D0CDC /* FSTTreeSortedDictionaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE2EF0841F3D0B6E003D0CDC /* FSTTreeSortedDictionaryTests.m */; };
DE65B16F21FFAEA300CC4A09 /* FSTAPIHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04E202154AA00B64F25 /* FSTAPIHelpers.mm */; };
DE65B17021FFAECB00CC4A09 /* FSTHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03A2021401F00B64F25 /* FSTHelpers.mm */; };
DE958C0521FA82D200E6C1C5 /* CodableTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE958C0421FA82D200E6C1C5 /* CodableTimestampTests.swift */; };
EBFC611B1BF195D0EC710AF4 /* app_testing.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5467FB07203E6A44009C9584 /* app_testing.mm */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -556,6 +560,7 @@
DE03B2E91F2149D600A30B9C /* Firestore_IntegrationTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Firestore_IntegrationTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
DE03B3621F215E1600A30B9C /* CAcert.pem */ = {isa = PBXFileReference; lastKnownFileType = text; path = CAcert.pem; sourceTree = "<group>"; };
DE0761F61F2FE68D003233AF /* BasicCompileTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCompileTests.swift; sourceTree = "<group>"; };
DE26C61521C15FCC00DE141A /* CodableDocumentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CodableDocumentTests.swift; sourceTree = "<group>"; };
DE2EF07E1F3D0B6E003D0CDC /* FSTArraySortedDictionaryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FSTArraySortedDictionaryTests.m; path = ../../third_party/Immutable/Tests/FSTArraySortedDictionaryTests.m; sourceTree = "<group>"; };
DE2EF07F1F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "FSTImmutableSortedDictionary+Testing.h"; path = "../../third_party/Immutable/Tests/FSTImmutableSortedDictionary+Testing.h"; sourceTree = "<group>"; };
DE2EF0801F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "FSTImmutableSortedDictionary+Testing.m"; path = "../../third_party/Immutable/Tests/FSTImmutableSortedDictionary+Testing.m"; sourceTree = "<group>"; };
Expand All @@ -568,6 +573,8 @@
DE51B1981F0D48AC0013853F /* FSTSpecTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FSTSpecTests.h; sourceTree = "<group>"; };
DE51B19A1F0D48AC0013853F /* FSTSyncEngineTestDriver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FSTSyncEngineTestDriver.h; sourceTree = "<group>"; };
DE51B1A71F0D48AC0013853F /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
DE84BBB821C1951E0048A176 /* BridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BridgingHeader.h; sourceTree = "<group>"; };
DE958C0421FA82D200E6C1C5 /* CodableTimestampTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CodableTimestampTests.swift; sourceTree = "<group>"; };
DF148C0D5EEC4A2CD9FA484C /* Pods-macOS_example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-macOS_example.release.xcconfig"; path = "Pods/Target Support Files/Pods-macOS_example/Pods-macOS_example.release.xcconfig"; sourceTree = "<group>"; };
E42355285B9EF55ABD785792 /* Pods_macOS_example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_macOS_example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E592181BFD7C53C305123739 /* Pods-Firestore_Tests_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests_iOS/Pods-Firestore_Tests_iOS.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -780,7 +787,9 @@
5495EB012040E90200EBA509 /* Codable */ = {
isa = PBXGroup;
children = (
DE26C61521C15FCC00DE141A /* CodableDocumentTests.swift */,
5495EB022040E90200EBA509 /* CodableGeoPointTests.swift */,
DE958C0421FA82D200E6C1C5 /* CodableTimestampTests.swift */,
);
path = Codable;
sourceTree = "<group>";
Expand All @@ -802,6 +811,7 @@
544A20ED20F6C046004E52CD /* API */,
5495EB012040E90200EBA509 /* Codable */,
54C9EDF52040E16300A969CD /* Info.plist */,
DE84BBB821C1951E0048A176 /* BridgingHeader.h */,
);
name = SwiftTests;
path = ../Swift/Tests;
Expand Down Expand Up @@ -1462,6 +1472,7 @@
TargetAttributes = {
54C9EDF02040E16300A969CD = {
CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 1010;
ProvisioningStyle = Automatic;
TestTargetID = 6003F589195388D20070C39A;
};
Expand Down Expand Up @@ -1937,8 +1948,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DE65B16F21FFAEA300CC4A09 /* FSTAPIHelpers.mm in Sources */,
DE65B17021FFAECB00CC4A09 /* FSTHelpers.mm in Sources */,
544A20EE20F6C10C004E52CD /* BasicCompileTests.swift in Sources */,
5495EB032040E90200EBA509 /* CodableGeoPointTests.swift in Sources */,
DE26C61621C15FCC00DE141A /* CodableDocumentTests.swift in Sources */,
DE958C0521FA82D200E6C1C5 /* CodableTimestampTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2259,15 +2274,21 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_NO_COMMON_BLOCKS = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_ROOT}/../../..\"",
"\"${PODS_ROOT}/../../../Firestore/third_party/abseil-cpp\"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be required and is likely harmful. We don't want any C++ when compiling Swift.

Same for the Release configuration below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what happens without the abseil include building the swift tests:

In file included from /Users/paulbeusterien/gh/firebase-ios-sdk/Firestore/Example/Tests/API/FSTAPIHelpers.mm:25:
In file included from /Users/paulbeusterien/gh/firebase-ios-sdk/Firestore/Example/Tests/Util/FSTHelpers.h:22:
In file included from /Users/paulbeusterien/gh/firebase-ios-sdk/Firestore/Source/Model/FSTDocument.h:19:
In file included from /Users/paulbeusterien/gh/firebase-ios-sdk/Firestore/core/src/firebase/firestore/model/document_key.h:26:
In file included from /Users/paulbeusterien/gh/firebase-ios-sdk/Firestore/Source/Model/FSTDocumentKey.h:22:
In file included from /Users/paulbeusterien/gh/firebase-ios-sdk/Firestore/core/src/firebase/firestore/model/resource_path.h:24:
In file included from /Users/paulbeusterien/gh/firebase-ios-sdk/Firestore/core/src/firebase/firestore/model/base_path.h:27:
In file included from /Users/paulbeusterien/gh/firebase-ios-sdk/Firestore/core/src/firebase/firestore/util/hard_assert.h:23:
In file included from /Users/paulbeusterien/gh/firebase-ios-sdk/Firestore/core/src/firebase/firestore/util/string_format.h:24:
/Users/paulbeusterien/gh/firebase-ios-sdk/Firestore/core/src/firebase/firestore/util/string_apple.h:29:10: fatal error: 'absl/strings/string_view.h' file not found
#include "absl/strings/string_view.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

);
INFOPLIST_FILE = ../Swift/Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Firestore-SwiftTests-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OBJC_BRIDGING_HEADER = ../Swift/Tests/BridgingHeader.h;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
paulb777 marked this conversation as resolved.
Show resolved Hide resolved
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Firestore_Example_iOS.app/Firestore_Example_iOS";
};
Expand Down Expand Up @@ -2298,14 +2319,20 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_NO_COMMON_BLOCKS = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_ROOT}/../../..\"",
"\"${PODS_ROOT}/../../../Firestore/third_party/abseil-cpp\"",
);
INFOPLIST_FILE = ../Swift/Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Firestore-SwiftTests-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = ../Swift/Tests/BridgingHeader.h;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Firestore_Example_iOS.app/Firestore_Example_iOS";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "54269AE8203B9FFC0039F03F"
BuildableName = "Firestore_SwiftTests_iOS.xctest"
BlueprintName = "Firestore_SwiftTests_iOS"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
Expand Down
1 change: 1 addition & 0 deletions Firestore/Example/Tests/API/FIRQueryTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "Firestore/Source/Core/FSTQuery.h"

#import "Firestore/Example/Tests/API/FSTAPIHelpers.h"
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
wilhuff marked this conversation as resolved.
Show resolved Hide resolved

NS_ASSUME_NONNULL_BEGIN

Expand Down
15 changes: 7 additions & 8 deletions Firestore/Example/Tests/API/FSTAPIHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

#import <Foundation/Foundation.h>

#import "Firestore/Example/Tests/Util/FSTHelpers.h"

#include "absl/strings/string_view.h"

@class FIRCollectionReference;
@class FIRDocumentReference;
@class FIRDocumentSnapshot;
@class FIRFirestore;
@class FIRQuerySnapshot;

/** Allow tests to just use an int literal for versions. */
typedef int64_t FSTTestSnapshotVersion;

NS_ASSUME_NONNULL_BEGIN

#if __cplusplus
Expand All @@ -36,17 +35,17 @@ extern "C" {
FIRFirestore *FSTTestFirestore();

/** A convenience method for creating a doc snapshot for tests. */
FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path,
FIRDocumentSnapshot *FSTTestDocSnapshot(const char *path,
FSTTestSnapshotVersion version,
NSDictionary<NSString *, id> *_Nullable data,
BOOL hasMutations,
BOOL fromCache);

/** A convenience method for creating a collection reference from a path string. */
FIRCollectionReference *FSTTestCollectionRef(const absl::string_view path);
FIRCollectionReference *FSTTestCollectionRef(const char *path);

/** A convenience method for creating a document reference from a path string. */
FIRDocumentReference *FSTTestDocRef(const absl::string_view path);
FIRDocumentReference *FSTTestDocRef(const char *path);

/**
* A convenience method for creating a particular query snapshot for tests.
Expand All @@ -63,7 +62,7 @@ FIRDocumentReference *FSTTestDocRef(const absl::string_view path);
* @returns A query snapshot that consists of both sets of documents.
*/
FIRQuerySnapshot *FSTTestQuerySnapshot(
const absl::string_view path,
const char *path,
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *oldDocs,
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
BOOL hasPendingWrites,
Expand Down
9 changes: 5 additions & 4 deletions Firestore/Example/Tests/API/FSTAPIHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <string>

#import "Firestore/Example/Tests/Util/FSTHelpers.h"
#import "Firestore/Source/API/FIRCollectionReference+Internal.h"
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
#import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h"
Expand Down Expand Up @@ -60,7 +61,7 @@
return sharedInstance;
}

FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path,
FIRDocumentSnapshot *FSTTestDocSnapshot(const char *path,
FSTTestSnapshotVersion version,
NSDictionary<NSString *, id> *_Nullable data,
BOOL hasMutations,
Expand All @@ -76,19 +77,19 @@
hasPendingWrites:hasMutations];
}

FIRCollectionReference *FSTTestCollectionRef(const absl::string_view path) {
FIRCollectionReference *FSTTestCollectionRef(const char *path) {
return [FIRCollectionReference referenceWithPath:testutil::Resource(path)
firestore:FSTTestFirestore()];
}

FIRDocumentReference *FSTTestDocRef(const absl::string_view path) {
FIRDocumentReference *FSTTestDocRef(const char *path) {
return [FIRDocumentReference referenceWithPath:testutil::Resource(path)
firestore:FSTTestFirestore()];
}

/** A convenience method for creating a query snapshots for tests. */
FIRQuerySnapshot *FSTTestQuerySnapshot(
const absl::string_view path,
const char *path,
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *oldDocs,
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
BOOL hasPendingWrites,
Expand Down
23 changes: 23 additions & 0 deletions Firestore/Swift/Source/Codable/CodableErrors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2019 Google
*
* 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.
*/

public enum FirestoreDecodingError: Error {
case decodingIsNotSupported
}

public enum FirestoreEncodingError: Error {
case encodingIsNotSupported
}
24 changes: 24 additions & 0 deletions Firestore/Swift/Source/Codable/CodablePassThroughTypes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2019 Google
*
* 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.
*/

import Foundation
import FirebaseFirestore

internal func isFirestorePassthroughType<T: Any>(_ value: T) -> Bool {
return
T.self == GeoPoint.self ||
T.self == Timestamp.self
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 Google
* Copyright 2019 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,10 +19,10 @@ import FirebaseFirestore
/**
* A protocol describing the encodable properties of a GeoPoint.
*
* Note: this protocol exists as a workaround for the Swift compiler: if the GeoPoint class was
* extended directly to conform to Codable, the methods implementing the protcol would be need to be
* marked required but that can't be done in an extension. Declaring the extension on the protocol
* sidesteps this issue.
* Note: this protocol exists as a workaround for the Swift compiler: if the GeoPoint class
* was extended directly to conform to Codable, the methods implementing the protocol would be need
* to be marked required but that can't be done in an extension. Declaring the extension on the
* protocol sidesteps this issue.
*/
fileprivate protocol CodableGeoPoint: Codable {
var latitude: Double { get }
Expand Down
62 changes: 62 additions & 0 deletions Firestore/Swift/Source/Codable/Timestamp+Codable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2019 Google
*
* 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.
*/

import FirebaseFirestore

/**
* A protocol describing the encodable properties of a Timestamp.
*
* Note: this protocol exists as a workaround for the Swift compiler: if the Timestamp class
* was extended directly to conform to Codable, the methods implementing the protocol would be need
* to be marked required but that can't be done in an extension. Declaring the extension on the
* protocol sidesteps this issue.
*/
fileprivate protocol CodableTimestamp: Codable {
var seconds: Int64 { get }
var nanoseconds: Int32 { get }

init(seconds: Int64, nanoseconds: Int32)
}

/** The keys in a GeoPoint. Must match the properties of CodableGeoPoint. */
fileprivate enum TimestampKeys: String, CodingKey {
case seconds
case nanoseconds
}

/**
* An extension of GeoPoint that implements the behavior of the Codable protocol.
*
* Note: this is implemented manually here because the Swift compiler can't synthesize these methods
* when declaring an extension to conform to Codable.
*/
extension CodableTimestamp {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: TimestampKeys.self)
let seconds = try container.decode(Int64.self, forKey: .seconds)
let nanoseconds = try container.decode(Int32.self, forKey: .nanoseconds)
self.init(seconds: seconds, nanoseconds: nanoseconds)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: TimestampKeys.self)
try container.encode(seconds, forKey: .seconds)
try container.encode(nanoseconds, forKey: .nanoseconds)
}
}

/** Extends GeoPoint to conform to Codable. */
extension Timestamp: CodableTimestamp {}
Loading