Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "Firestore/core/src/model/types.h"
#include "Firestore/core/src/nanopb/message.h"
#include "Firestore/core/src/nanopb/nanopb_util.h"
#include "Firestore/core/src/remote/bloom_filter.h"
#include "Firestore/core/src/remote/existence_filter.h"
#include "Firestore/core/src/remote/serializer.h"
#include "Firestore/core/src/remote/watch_change.h"
Expand All @@ -71,6 +72,7 @@
#include "Firestore/core/src/util/to_string.h"
#include "Firestore/core/test/unit/testutil/testutil.h"
#include "absl/memory/memory.h"
#include "absl/strings/escaping.h"
#include "absl/types/optional.h"

namespace objc = firebase::firestore::objc;
Expand Down Expand Up @@ -98,6 +100,7 @@
using firebase::firestore::nanopb::ByteString;
using firebase::firestore::nanopb::MakeByteString;
using firebase::firestore::nanopb::Message;
using firebase::firestore::remote::BloomFilter;
using firebase::firestore::remote::DocumentWatchChange;
using firebase::firestore::remote::ExistenceFilter;
using firebase::firestore::remote::ExistenceFilterWatchChange;
Expand All @@ -115,6 +118,7 @@
using firebase::firestore::util::MakeStringPtr;
using firebase::firestore::util::Path;
using firebase::firestore::util::Status;
using firebase::firestore::util::StatusOr;
using firebase::firestore::util::TimerId;
using firebase::firestore::util::ToString;
using firebase::firestore::util::WrapCompare;
Expand Down Expand Up @@ -325,6 +329,13 @@ - (SnapshotVersion)parseVersion:(NSNumber *_Nullable)version {
return Version(version.longLongValue);
}

- (absl::optional<BloomFilter>)parseBloomFilter:(NSDictionary *_Nullable)bloomFilterProto {
// TODO(Mila): None of the ported spec tests actually has the bloom filter json string, so hard
// code a null value for now. Actual parsing code will be written in the next PR, where we can
// validate the parsing result.
return absl::nullopt;
}

- (DocumentViewChange)parseChange:(NSDictionary *)jsonDoc ofType:(DocumentViewChange::Type)type {
NSNumber *version = jsonDoc[@"version"];
NSDictionary *options = jsonDoc[@"options"];
Expand Down Expand Up @@ -463,14 +474,17 @@ - (void)doWatchEntity:(NSDictionary *)watchEntity {
}
}

- (void)doWatchFilter:(NSArray *)watchFilter {
NSArray<NSNumber *> *targets = watchFilter[0];
- (void)doWatchFilter:(NSDictionary *)watchFilter {
NSArray<NSNumber *> *targets = watchFilter[@"targetIds"];
HARD_ASSERT(targets.count == 1, "ExistenceFilters currently support exactly one target only.");

int keyCount = watchFilter.count == 0 ? 0 : (int)watchFilter.count - 1;
NSArray<NSNumber *> *keys = watchFilter[@"keys"];
int keyCount = keys ? (int)keys.count : 0;

absl::optional<BloomFilter> bloomFilter = [self parseBloomFilter:watchFilter[@"bloomFilter"]];

ExistenceFilter filter{keyCount};
ExistenceFilterWatchChange change{filter, targets[0].intValue};
ExistenceFilter filter{keyCount, std::move(bloomFilter)};
ExistenceFilterWatchChange change{std::move(filter), targets[0].intValue};
[self.driver receiveWatchChange:change snapshotVersion:SnapshotVersion::None()];
}

Expand Down
114 changes: 67 additions & 47 deletions Firestore/Example/Tests/SpecTests/json/existence_filter_spec_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -358,13 +360,15 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1",
"collection/2"
],
"collection/1",
"collection/2"
]
"targetIds": [
2
]
}
},
{
"watchEntity": {
Expand Down Expand Up @@ -712,11 +716,13 @@
}
},
{
"watchFilter": [
[
"watchFilter": {
"keys": [
],
"targetIds": [
2
]
]
}
},
{
"watchRemove": {
Expand Down Expand Up @@ -889,12 +895,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1178,12 +1186,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1287,12 +1297,14 @@
}
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1458,12 +1470,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1809,12 +1823,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -2108,11 +2124,13 @@
]
},
{
"watchFilter": [
[
"watchFilter": {
"keys": [
],
"targetIds": [
2
]
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -2223,12 +2241,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down
25 changes: 14 additions & 11 deletions Firestore/Example/Tests/SpecTests/json/limbo_spec_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3409,11 +3409,13 @@
]
},
{
"watchFilter": [
[
"watchFilter": {
"keys": [
],
"targetIds": [
1
]
]
}
},
{
"watchCurrent": [
Expand Down Expand Up @@ -8081,15 +8083,16 @@
}
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/b1",
"collection/b2",
"collection/b3"
],
"collection/b1",
"collection/b2",
"collection/b3"
]

"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down
12 changes: 7 additions & 5 deletions Firestore/Example/Tests/SpecTests/json/limit_spec_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5464,12 +5464,14 @@
}
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/b"
],
"collection/b"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const pb_field_t google_firestore_v1_BitSequence_fields[3] = {
};

const pb_field_t google_firestore_v1_BloomFilter_fields[3] = {
PB_FIELD( 1, MESSAGE , SINGULAR, STATIC , FIRST, google_firestore_v1_BloomFilter, bits, bits, &google_firestore_v1_BitSequence_fields),
PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, google_firestore_v1_BloomFilter, bits, bits, &google_firestore_v1_BitSequence_fields),
PB_FIELD( 2, INT32 , SINGULAR, STATIC , OTHER, google_firestore_v1_BloomFilter, hash_count, bits, 0),
PB_LAST_FIELD
};
Expand Down Expand Up @@ -96,7 +96,9 @@ std::string google_firestore_v1_BloomFilter::ToString(int indent) const {
std::string tostring_header = PrintHeader(indent, "BloomFilter", this);
std::string tostring_result;

tostring_result += PrintMessageField("bits ", bits, indent + 1, false);
if (has_bits) {
tostring_result += PrintMessageField("bits ", bits, indent + 1, true);
}
tostring_result += PrintPrimitiveField("hash_count: ",
hash_count, indent + 1, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef struct _google_firestore_v1_BitSequence {
} google_firestore_v1_BitSequence;

typedef struct _google_firestore_v1_BloomFilter {
bool has_bits;
google_firestore_v1_BitSequence bits;
int32_t hash_count;

Expand All @@ -53,9 +54,9 @@ typedef struct _google_firestore_v1_BloomFilter {

/* Initializer values for message structs */
#define google_firestore_v1_BitSequence_init_default {NULL, 0}
#define google_firestore_v1_BloomFilter_init_default {google_firestore_v1_BitSequence_init_default, 0}
#define google_firestore_v1_BloomFilter_init_default {false, google_firestore_v1_BitSequence_init_default, 0}
#define google_firestore_v1_BitSequence_init_zero {NULL, 0}
#define google_firestore_v1_BloomFilter_init_zero {google_firestore_v1_BitSequence_init_zero, 0}
#define google_firestore_v1_BloomFilter_init_zero {false, google_firestore_v1_BitSequence_init_zero, 0}

/* Field tags (for use in manual encoding/decoding) */
#define google_firestore_v1_BitSequence_bitmap_tag 1
Expand Down
8 changes: 5 additions & 3 deletions Firestore/Protos/nanopb/google/firestore/v1/write.nanopb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const pb_field_t google_firestore_v1_DocumentRemove_fields[4] = {
const pb_field_t google_firestore_v1_ExistenceFilter_fields[4] = {
PB_FIELD( 1, INT32 , SINGULAR, STATIC , FIRST, google_firestore_v1_ExistenceFilter, target_id, target_id, 0),
PB_FIELD( 2, INT32 , SINGULAR, STATIC , OTHER, google_firestore_v1_ExistenceFilter, count, target_id, 0),
PB_FIELD( 3, MESSAGE , SINGULAR, STATIC , OTHER, google_firestore_v1_ExistenceFilter, unchanged_names, count, &google_firestore_v1_BloomFilter_fields),
PB_FIELD( 3, MESSAGE , OPTIONAL, STATIC , OTHER, google_firestore_v1_ExistenceFilter, unchanged_names, count, &google_firestore_v1_BloomFilter_fields),
PB_LAST_FIELD
};

Expand Down Expand Up @@ -317,8 +317,10 @@ std::string google_firestore_v1_ExistenceFilter::ToString(int indent) const {
target_id, indent + 1, false);
tostring_result += PrintPrimitiveField("count: ",
count, indent + 1, false);
tostring_result += PrintMessageField("unchanged_names ",
unchanged_names, indent + 1, false);
if (has_unchanged_names) {
tostring_result += PrintMessageField("unchanged_names ",
unchanged_names, indent + 1, true);
}

std::string tostring_tail = PrintTail(indent);
return tostring_header + tostring_result + tostring_tail;
Expand Down
Loading