FSTSerializerBeta.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "Firestore/core/include/firebase/firestore/timestamp.h"
  18. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  19. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  20. #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
  21. @class FSTFieldValue;
  22. @class FSTMaybeDocument;
  23. @class FSTMutation;
  24. @class FSTMutationBatch;
  25. @class FSTMutationResult;
  26. @class FSTObjectValue;
  27. @class FSTQuery;
  28. @class FSTQueryData;
  29. @class FSTWatchChange;
  30. @class GCFSBatchGetDocumentsResponse;
  31. @class GCFSDocument;
  32. @class GCFSDocumentMask;
  33. @class GCFSListenResponse;
  34. @class GCFSTarget;
  35. @class GCFSTarget_DocumentsTarget;
  36. @class GCFSTarget_QueryTarget;
  37. @class GCFSValue;
  38. @class GCFSWrite;
  39. @class GCFSWriteResult;
  40. @class GPBTimestamp;
  41. NS_ASSUME_NONNULL_BEGIN
  42. /**
  43. * Converts internal model objects to their equivalent protocol buffer form. Methods starting with
  44. * "encoded" convert to a protocol buffer and methods starting with "decoded" convert from a
  45. * protocol buffer.
  46. *
  47. * Throws an exception if a protocol buffer is missing a critical field or has a value we can't
  48. * interpret.
  49. */
  50. @interface FSTSerializerBeta : NSObject
  51. - (instancetype)init NS_UNAVAILABLE;
  52. - (instancetype)initWithDatabaseID:(const firebase::firestore::model::DatabaseId *)databaseID
  53. NS_DESIGNATED_INITIALIZER;
  54. - (GPBTimestamp *)encodedTimestamp:(const firebase::Timestamp &)timestamp;
  55. - (firebase::Timestamp)decodedTimestamp:(GPBTimestamp *)timestamp;
  56. - (GPBTimestamp *)encodedVersion:(const firebase::firestore::model::SnapshotVersion &)version;
  57. - (firebase::firestore::model::SnapshotVersion)decodedVersion:(GPBTimestamp *)version;
  58. /** Returns the database ID, such as `projects/{project id}/databases/{database_id}`. */
  59. - (NSString *)encodedDatabaseID;
  60. /**
  61. * Encodes the given document key as a fully qualified name. This includes the
  62. * databaseId associated with this FSTSerializerBeta and the key path.
  63. */
  64. - (NSString *)encodedDocumentKey:(const firebase::firestore::model::DocumentKey &)key;
  65. - (firebase::firestore::model::DocumentKey)decodedDocumentKey:(NSString *)key;
  66. - (GCFSValue *)encodedFieldValue:(FSTFieldValue *)fieldValue;
  67. - (FSTFieldValue *)decodedFieldValue:(GCFSValue *)valueProto;
  68. - (GCFSWrite *)encodedMutation:(FSTMutation *)mutation;
  69. - (FSTMutation *)decodedMutation:(GCFSWrite *)mutation;
  70. - (FSTMutationResult *)decodedMutationResult:(GCFSWriteResult *)mutation
  71. commitVersion:(const firebase::firestore::model::SnapshotVersion &)
  72. commitVersion;
  73. - (nullable NSMutableDictionary<NSString *, NSString *> *)encodedListenRequestLabelsForQueryData:
  74. (FSTQueryData *)queryData;
  75. - (GCFSTarget *)encodedTarget:(FSTQueryData *)queryData;
  76. - (GCFSTarget_DocumentsTarget *)encodedDocumentsTarget:(FSTQuery *)query;
  77. - (FSTQuery *)decodedQueryFromDocumentsTarget:(GCFSTarget_DocumentsTarget *)target;
  78. - (GCFSTarget_QueryTarget *)encodedQueryTarget:(FSTQuery *)query;
  79. - (FSTQuery *)decodedQueryFromQueryTarget:(GCFSTarget_QueryTarget *)target;
  80. - (FSTWatchChange *)decodedWatchChange:(GCFSListenResponse *)watchChange;
  81. - (firebase::firestore::model::SnapshotVersion)versionFromListenResponse:
  82. (GCFSListenResponse *)watchChange;
  83. - (GCFSDocument *)encodedDocumentWithFields:(FSTObjectValue *)objectValue
  84. key:(const firebase::firestore::model::DocumentKey &)key;
  85. /**
  86. * Encodes an FSTObjectValue into a dictionary.
  87. * @return a new dictionary that can be assigned to a field in another proto.
  88. */
  89. - (NSMutableDictionary<NSString *, GCFSValue *> *)encodedFields:(FSTObjectValue *)value;
  90. - (FSTObjectValue *)decodedFields:(NSDictionary<NSString *, GCFSValue *> *)fields;
  91. - (FSTMaybeDocument *)decodedMaybeDocumentFromBatch:(GCFSBatchGetDocumentsResponse *)response;
  92. @end
  93. NS_ASSUME_NONNULL_END