FSTSerializerBeta.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. @class FSTDatabaseID;
  18. @class FSTDocumentKey;
  19. @class FSTFieldValue;
  20. @class FSTMaybeDocument;
  21. @class FSTMutation;
  22. @class FSTMutationBatch;
  23. @class FSTMutationResult;
  24. @class FSTObjectValue;
  25. @class FSTQuery;
  26. @class FSTQueryData;
  27. @class FSTSnapshotVersion;
  28. @class FSTTimestamp;
  29. @class FSTWatchChange;
  30. @class GCFSBatchGetDocumentsResponse;
  31. @class GCFSDocument;
  32. @class GCFSDocumentMask;
  33. @class GCFSListenResponse;
  34. @class GCFSTarget;
  35. @class GCFSTarget_DocumentsTarget;
  36. @class GCFSTarget_QueryTarget;
  37. @class GCFSValue;
  38. @class GCFSWrite;
  39. @class GCFSWriteResult;
  40. @class GPBTimestamp;
  41. NS_ASSUME_NONNULL_BEGIN
  42. /**
  43. * Converts internal model objects to their equivalent protocol buffer form. Methods starting with
  44. * "encoded" convert to a protocol buffer and methods starting with "decoded" convert from a
  45. * protocol buffer.
  46. *
  47. * Throws an exception if a protocol buffer is missing a critical field or has a value we can't
  48. * interpret.
  49. */
  50. @interface FSTSerializerBeta : NSObject
  51. - (instancetype)init NS_UNAVAILABLE;
  52. - (instancetype)initWithDatabaseID:(FSTDatabaseID *)databaseID NS_DESIGNATED_INITIALIZER;
  53. - (GPBTimestamp *)encodedTimestamp:(FSTTimestamp *)timestamp;
  54. - (FSTTimestamp *)decodedTimestamp:(GPBTimestamp *)timestamp;
  55. - (GPBTimestamp *)encodedVersion:(FSTSnapshotVersion *)version;
  56. - (FSTSnapshotVersion *)decodedVersion:(GPBTimestamp *)version;
  57. /** Returns the database ID, such as `projects/{project id}/databases/{database_id}`. */
  58. - (NSString *)encodedDatabaseID;
  59. - (NSString *)encodedDocumentKey:(FSTDocumentKey *)key;
  60. - (FSTDocumentKey *)decodedDocumentKey:(NSString *)key;
  61. - (GCFSValue *)encodedFieldValue:(FSTFieldValue *)fieldValue;
  62. - (FSTFieldValue *)decodedFieldValue:(GCFSValue *)valueProto;
  63. - (GCFSWrite *)encodedMutation:(FSTMutation *)mutation;
  64. - (FSTMutation *)decodedMutation:(GCFSWrite *)mutation;
  65. - (FSTMutationResult *)decodedMutationResult:(GCFSWriteResult *)mutation;
  66. - (nullable NSMutableDictionary<NSString *, NSString *> *)encodedListenRequestLabelsForQueryData:
  67. (FSTQueryData *)queryData;
  68. - (GCFSTarget *)encodedTarget:(FSTQueryData *)queryData;
  69. - (GCFSTarget_DocumentsTarget *)encodedDocumentsTarget:(FSTQuery *)query;
  70. - (FSTQuery *)decodedQueryFromDocumentsTarget:(GCFSTarget_DocumentsTarget *)target;
  71. - (GCFSTarget_QueryTarget *)encodedQueryTarget:(FSTQuery *)query;
  72. - (FSTQuery *)decodedQueryFromQueryTarget:(GCFSTarget_QueryTarget *)target;
  73. - (FSTWatchChange *)decodedWatchChange:(GCFSListenResponse *)watchChange;
  74. - (FSTSnapshotVersion *)versionFromListenResponse:(GCFSListenResponse *)watchChange;
  75. - (GCFSDocument *)encodedDocumentWithFields:(FSTObjectValue *)objectValue key:(FSTDocumentKey *)key;
  76. /**
  77. * Encodes an FSTObjectValue into a dictionary.
  78. * @return a new dictionary that can be assigned to a field in another proto.
  79. */
  80. - (NSMutableDictionary<NSString *, GCFSValue *> *)encodedFields:(FSTObjectValue *)value;
  81. - (FSTObjectValue *)decodedFields:(NSDictionary<NSString *, GCFSValue *> *)fields;
  82. - (FSTMaybeDocument *)decodedMaybeDocumentFromBatch:(GCFSBatchGetDocumentsResponse *)response;
  83. @end
  84. NS_ASSUME_NONNULL_END