Skip to content

Commit 89aa149

Browse files
committed
[realppl 5] map,string,timestamp and mirroring semantics
1 parent 3cc1d68 commit 89aa149

File tree

11 files changed

+3738
-288
lines changed

11 files changed

+3738
-288
lines changed

Firestore/core/src/core/expressions_eval.cc

Lines changed: 1332 additions & 182 deletions
Large diffs are not rendered by default.

Firestore/core/src/core/expressions_eval.h

Lines changed: 372 additions & 21 deletions
Large diffs are not rendered by default.

Firestore/core/src/model/object_value.cc

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,40 +50,6 @@ using nanopb::Message;
5050
using nanopb::ReleaseFieldOwnership;
5151
using nanopb::SetRepeatedField;
5252

53-
struct MapEntryKeyCompare {
54-
bool operator()(const google_firestore_v1_MapValue_FieldsEntry& entry,
55-
absl::string_view segment) const {
56-
return nanopb::MakeStringView(entry.key) < segment;
57-
}
58-
bool operator()(absl::string_view segment,
59-
const google_firestore_v1_MapValue_FieldsEntry& entry) const {
60-
return segment < nanopb::MakeStringView(entry.key);
61-
}
62-
};
63-
64-
/**
65-
* Finds an entry by key in the provided map value. Returns `nullptr` if the
66-
* entry does not exist.
67-
*/
68-
google_firestore_v1_MapValue_FieldsEntry* FindEntry(
69-
const google_firestore_v1_Value& value, absl::string_view segment) {
70-
if (!IsMap(value)) {
71-
return nullptr;
72-
}
73-
const google_firestore_v1_MapValue& map_value = value.map_value;
74-
75-
// MapValues in iOS are always stored in sorted order.
76-
auto found = std::equal_range(map_value.fields,
77-
map_value.fields + map_value.fields_count,
78-
segment, MapEntryKeyCompare());
79-
80-
if (found.first == found.second) {
81-
return nullptr;
82-
}
83-
84-
return found.first;
85-
}
86-
8753
size_t CalculateSizeOfUnion(
8854
const google_firestore_v1_MapValue& map_value,
8955
const std::map<std::string, Message<google_firestore_v1_Value>>& upserts,

Firestore/core/src/model/value_util.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,20 @@ Message<google_firestore_v1_Value> RefValue(
955955
return result;
956956
}
957957

958+
Message<google_firestore_v1_Value> StringValue(const std::string& value) {
959+
Message<google_firestore_v1_Value> result;
960+
result->which_value_type = google_firestore_v1_Value_string_value_tag;
961+
result->reference_value = nanopb::MakeBytesArray(value);
962+
return result;
963+
}
964+
965+
Message<google_firestore_v1_Value> StringValue(absl::string_view value) {
966+
Message<google_firestore_v1_Value> result;
967+
result->which_value_type = google_firestore_v1_Value_string_value_tag;
968+
result->reference_value = nanopb::MakeBytesArray(value.data(), value.size());
969+
return result;
970+
}
971+
958972
Message<google_firestore_v1_Value> ArrayValue(
959973
std::vector<Message<google_firestore_v1_Value>> values) {
960974
google_firestore_v1_Value result;
@@ -1037,6 +1051,38 @@ absl::optional<int64_t> GetInteger(const google_firestore_v1_Value& value) {
10371051
return absl::nullopt;
10381052
}
10391053

1054+
namespace {
1055+
struct MapEntryKeyCompare {
1056+
bool operator()(const google_firestore_v1_MapValue_FieldsEntry& entry,
1057+
absl::string_view segment) const {
1058+
return nanopb::MakeStringView(entry.key) < segment;
1059+
}
1060+
bool operator()(absl::string_view segment,
1061+
const google_firestore_v1_MapValue_FieldsEntry& entry) const {
1062+
return segment < nanopb::MakeStringView(entry.key);
1063+
}
1064+
};
1065+
} // namespace
1066+
1067+
google_firestore_v1_MapValue_FieldsEntry* FindEntry(
1068+
const google_firestore_v1_Value& value, absl::string_view field) {
1069+
if (!IsMap(value)) {
1070+
return nullptr;
1071+
}
1072+
const google_firestore_v1_MapValue& map_value = value.map_value;
1073+
1074+
// MapValues in iOS are always stored in sorted order.
1075+
auto found = std::equal_range(map_value.fields,
1076+
map_value.fields + map_value.fields_count,
1077+
field, MapEntryKeyCompare());
1078+
1079+
if (found.first == found.second) {
1080+
return nullptr;
1081+
}
1082+
1083+
return found.first;
1084+
}
1085+
10401086
namespace {
10411087

10421088
StrictEqualsResult StrictArrayEquals(

Firestore/core/src/model/value_util.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ google_firestore_v1_Value MinMap();
248248
nanopb::Message<google_firestore_v1_Value> RefValue(
249249
const DatabaseId& database_id, const DocumentKey& document_key);
250250

251+
/**
252+
* Returns a Protobuf string value.
253+
*
254+
* The returned value might point to heap allocated memory that is owned by
255+
* this function. To take ownership of this memory, call `DeepClone`.
256+
*/
257+
nanopb::Message<google_firestore_v1_Value> StringValue(
258+
const std::string& value);
259+
260+
nanopb::Message<google_firestore_v1_Value> StringValue(absl::string_view value);
261+
251262
/**
252263
* Returns a Protobuf array value representing the given values.
253264
*
@@ -303,6 +314,13 @@ inline bool IsMap(const absl::optional<google_firestore_v1_Value>& value) {
303314
*/
304315
absl::optional<int64_t> GetInteger(const google_firestore_v1_Value& value);
305316

317+
/**
318+
* Finds an entry by key in the provided map value. Returns `nullptr` if the
319+
* entry does not exist.
320+
*/
321+
google_firestore_v1_MapValue_FieldsEntry* FindEntry(
322+
const google_firestore_v1_Value& value, absl::string_view field);
323+
306324
} // namespace model
307325

308326
inline bool operator==(const google_firestore_v1_Value& lhs,

0 commit comments

Comments
 (0)