File tree 3 files changed +21
-8
lines changed
3 files changed +21
-8
lines changed Original file line number Diff line number Diff line change 24
24
#include " Firestore/core/src/nanopb/fields_array.h"
25
25
#include " Firestore/core/src/nanopb/message.h"
26
26
#include " Firestore/core/src/nanopb/nanopb_util.h"
27
+ #include " Firestore/core/src/util/hashing.h"
27
28
#include " absl/types/span.h"
28
29
29
30
namespace firebase {
@@ -53,6 +54,7 @@ struct MapEntryKeyCompare {
53
54
}
54
55
};
55
56
57
+ /* * Traverses a Value proto and sorts all MapValues by key. */
56
58
void SortFields (google_firestore_v1_Value& value) {
57
59
if (value.which_value_type == google_firestore_v1_Value_map_value_tag) {
58
60
google_firestore_v1_MapValue& map_value = value.map_value ;
@@ -355,7 +357,7 @@ std::string ObjectValue::ToString() const {
355
357
}
356
358
357
359
size_t ObjectValue::Hash () const {
358
- return std::hash<std::string>() (CanonicalId (*value_));
360
+ return util::Hash (CanonicalId (*value_));
359
361
}
360
362
361
363
/* *
Original file line number Diff line number Diff line change @@ -45,12 +45,23 @@ class ObjectValue {
45
45
explicit ObjectValue (const google_firestore_v1_Value& value);
46
46
47
47
ObjectValue (ObjectValue&& other) noexcept = default ;
48
- ObjectValue& operator =(ObjectValue&& other) = default ;
48
+ ObjectValue& operator =(ObjectValue&& other) noexcept = default ;
49
49
ObjectValue (const ObjectValue& other);
50
50
51
51
ObjectValue& operator =(const ObjectValue&) = delete ;
52
52
53
+ /* *
54
+ * Creates a new ObjectValue that is backed by the given `map_value`.
55
+ * ObjectValue takes on ownership of the data.
56
+ */
53
57
static ObjectValue FromMapValue (google_firestore_v1_MapValue map_value);
58
+
59
+ /* *
60
+ * Creates a new ObjectValue that is backed by the provided document fields.
61
+ * ObjectValue takes on ownership of the data and zeroes out the pointers in
62
+ * `fields_entry`. This allows the callsite to destruct the Document proto
63
+ * without affecting the fields data.
64
+ */
54
65
static ObjectValue FromFieldsEntry (
55
66
google_firestore_v1_Document_FieldsEntry* fields_entry, pb_size_t count);
56
67
Original file line number Diff line number Diff line change @@ -48,13 +48,13 @@ TEST_F(ObjectValueTest, ExtractsFields) {
48
48
ASSERT_EQ (google_firestore_v1_Value_map_value_tag,
49
49
value.Get (Field (" foo" ))->which_value_type );
50
50
51
- EXPECT_TRUE (Value (1 ) == *value.Get (Field (" foo.a" )));
52
- EXPECT_TRUE (Value (true ) == *value.Get (Field (" foo.b" )));
53
- EXPECT_TRUE (Value (" string" ) == *value.Get (Field (" foo.c" )));
51
+ EXPECT_EQ (Value (1 ), *value.Get (Field (" foo.a" )));
52
+ EXPECT_EQ (Value (true ), *value.Get (Field (" foo.b" )));
53
+ EXPECT_EQ (Value (" string" ), *value.Get (Field (" foo.c" )));
54
54
55
- EXPECT_TRUE (nullopt == value.Get (Field (" foo.a.b" )));
56
- EXPECT_TRUE (nullopt == value.Get (Field (" bar" )));
57
- EXPECT_TRUE (nullopt == value.Get (Field (" bar.a" )));
55
+ EXPECT_EQ (nullopt, value.Get (Field (" foo.a.b" )));
56
+ EXPECT_EQ (nullopt, value.Get (Field (" bar" )));
57
+ EXPECT_EQ (nullopt, value.Get (Field (" bar.a" )));
58
58
}
59
59
60
60
TEST_F (ObjectValueTest, ExtractsFieldMask) {
You can’t perform that action at this time.
0 commit comments