FSTSerializerBeta.h 5.8 KB

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