FSTSerializerBeta.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #include <memory>
  18. #include "Firestore/core/include/firebase/firestore/timestamp.h"
  19. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  20. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  21. #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
  22. #include "Firestore/core/src/firebase/firestore/remote/watch_change.h"
  23. @class FSTFieldValue;
  24. @class FSTMaybeDocument;
  25. @class FSTMutation;
  26. @class FSTMutationBatch;
  27. @class FSTMutationResult;
  28. @class FSTObjectValue;
  29. @class FSTQuery;
  30. @class FSTQueryData;
  31. @class GCFSBatchGetDocumentsResponse;
  32. @class GCFSDocument;
  33. @class GCFSDocumentMask;
  34. @class GCFSListenResponse;
  35. @class GCFSTarget;
  36. @class GCFSTarget_DocumentsTarget;
  37. @class GCFSTarget_QueryTarget;
  38. @class GCFSValue;
  39. @class GCFSWrite;
  40. @class GCFSWriteResult;
  41. @class GPBTimestamp;
  42. NS_ASSUME_NONNULL_BEGIN
  43. /**
  44. * Converts internal model objects to their equivalent protocol buffer form. Methods starting with
  45. * "encoded" convert to a protocol buffer and methods starting with "decoded" convert from a
  46. * protocol buffer.
  47. *
  48. * Throws an exception if a protocol buffer is missing a critical field or has a value we can't
  49. * interpret.
  50. */
  51. @interface FSTSerializerBeta : NSObject
  52. - (instancetype)init NS_UNAVAILABLE;
  53. - (instancetype)initWithDatabaseID:(const firebase::firestore::model::DatabaseId *)databaseID
  54. NS_DESIGNATED_INITIALIZER;
  55. - (GPBTimestamp *)encodedTimestamp:(const firebase::Timestamp &)timestamp;
  56. - (firebase::Timestamp)decodedTimestamp:(GPBTimestamp *)timestamp;
  57. - (GPBTimestamp *)encodedVersion:(const firebase::firestore::model::SnapshotVersion &)version;
  58. - (firebase::firestore::model::SnapshotVersion)decodedVersion:(GPBTimestamp *)version;
  59. /** Returns the database ID, such as `projects/{project id}/databases/{database_id}`. */
  60. - (NSString *)encodedDatabaseID;
  61. /**
  62. * Encodes the given document key as a fully qualified name. This includes the
  63. * databaseId associated with this FSTSerializerBeta and the key path.
  64. */
  65. - (NSString *)encodedDocumentKey:(const firebase::firestore::model::DocumentKey &)key;
  66. - (firebase::firestore::model::DocumentKey)decodedDocumentKey:(NSString *)key;
  67. - (GCFSValue *)encodedFieldValue:(FSTFieldValue *)fieldValue;
  68. - (FSTFieldValue *)decodedFieldValue:(GCFSValue *)valueProto;
  69. - (GCFSWrite *)encodedMutation:(FSTMutation *)mutation;
  70. - (FSTMutation *)decodedMutation:(GCFSWrite *)mutation;
  71. - (FSTMutationResult *)decodedMutationResult:(GCFSWriteResult *)mutation
  72. commitVersion:(const firebase::firestore::model::SnapshotVersion &)
  73. commitVersion;
  74. - (nullable NSMutableDictionary<NSString *, NSString *> *)encodedListenRequestLabelsForQueryData:
  75. (FSTQueryData *)queryData;
  76. - (GCFSTarget *)encodedTarget:(FSTQueryData *)queryData;
  77. - (GCFSTarget_DocumentsTarget *)encodedDocumentsTarget:(FSTQuery *)query;
  78. - (FSTQuery *)decodedQueryFromDocumentsTarget:(GCFSTarget_DocumentsTarget *)target;
  79. - (GCFSTarget_QueryTarget *)encodedQueryTarget:(FSTQuery *)query;
  80. - (FSTQuery *)decodedQueryFromQueryTarget:(GCFSTarget_QueryTarget *)target;
  81. - (std::unique_ptr<firebase::firestore::remote::WatchChange>)decodedWatchChange:
  82. (GCFSListenResponse *)watchChange;
  83. - (firebase::firestore::model::SnapshotVersion)versionFromListenResponse:
  84. (GCFSListenResponse *)watchChange;
  85. - (GCFSDocument *)encodedDocumentWithFields:(FSTObjectValue *)objectValue
  86. key:(const firebase::firestore::model::DocumentKey &)key;
  87. /**
  88. * Encodes an FSTObjectValue into a dictionary.
  89. * @return a new dictionary that can be assigned to a field in another proto.
  90. */
  91. - (NSMutableDictionary<NSString *, GCFSValue *> *)encodedFields:(FSTObjectValue *)value;
  92. - (FSTObjectValue *)decodedFields:(NSDictionary<NSString *, GCFSValue *> *)fields;
  93. - (FSTMaybeDocument *)decodedMaybeDocumentFromBatch:(GCFSBatchGetDocumentsResponse *)response;
  94. @end
  95. NS_ASSUME_NONNULL_END