FSTSerializerBeta.h 5.3 KB

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