FSTSerializerBeta.h 5.7 KB

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