FSTSerializerBeta.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. namespace model = firebase::firestore::model;
  43. namespace remote = firebase::firestore::remote;
  44. NS_ASSUME_NONNULL_BEGIN
  45. /**
  46. * Converts internal model objects to their equivalent protocol buffer form. Methods starting with
  47. * "encoded" convert to a protocol buffer and methods starting with "decoded" convert from a
  48. * protocol buffer.
  49. *
  50. * Throws an exception if a protocol buffer is missing a critical field or has a value we can't
  51. * interpret.
  52. */
  53. @interface FSTSerializerBeta : NSObject
  54. - (instancetype)init NS_UNAVAILABLE;
  55. - (instancetype)initWithDatabaseID:(model::DatabaseId)databaseID NS_DESIGNATED_INITIALIZER;
  56. - (GPBTimestamp *)encodedTimestamp:(const firebase::Timestamp &)timestamp;
  57. - (firebase::Timestamp)decodedTimestamp:(GPBTimestamp *)timestamp;
  58. - (GPBTimestamp *)encodedVersion:(const model::SnapshotVersion &)version;
  59. - (model::SnapshotVersion)decodedVersion:(GPBTimestamp *)version;
  60. /** Returns the database ID, such as `projects/{project id}/databases/{database_id}`. */
  61. - (NSString *)encodedDatabaseID;
  62. /**
  63. * Encodes the given document key as a fully qualified name. This includes the
  64. * databaseId associated with this FSTSerializerBeta and the key path.
  65. */
  66. - (NSString *)encodedDocumentKey:(const model::DocumentKey &)key;
  67. - (model::DocumentKey)decodedDocumentKey:(NSString *)key;
  68. - (GCFSValue *)encodedFieldValue:(FSTFieldValue *)fieldValue;
  69. - (FSTFieldValue *)decodedFieldValue:(GCFSValue *)valueProto;
  70. - (GCFSWrite *)encodedMutation:(FSTMutation *)mutation;
  71. - (FSTMutation *)decodedMutation:(GCFSWrite *)mutation;
  72. - (FSTMutationResult *)decodedMutationResult:(GCFSWriteResult *)mutation
  73. commitVersion:(const model::SnapshotVersion &)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<remote::WatchChange>)decodedWatchChange:(GCFSListenResponse *)watchChange;
  82. - (model::SnapshotVersion)versionFromListenResponse:(GCFSListenResponse *)watchChange;
  83. - (GCFSDocument *)encodedDocumentWithFields:(FSTObjectValue *)objectValue
  84. key:(const 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