FSTSerializerBeta.h 5.6 KB

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