Skip to content

Commit 2ae36f1

Browse files
authored
[De]Serialize FieldValue map_values ("Objects") (#878)
These can (recursively) contain other FieldValues.
1 parent b7750b5 commit 2ae36f1

File tree

5 files changed

+421
-75
lines changed

5 files changed

+421
-75
lines changed

Firestore/core/src/firebase/firestore/model/field_value.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ FieldValue& FieldValue::operator=(const FieldValue& value) {
113113
}
114114
case Type::Object: {
115115
// copy-and-swap
116-
std::map<const std::string, const FieldValue> tmp = value.object_value_;
116+
std::map<std::string, FieldValue> tmp = value.object_value_;
117117
std::swap(object_value_, tmp);
118118
break;
119119
}
@@ -281,13 +281,12 @@ FieldValue FieldValue::ArrayValue(std::vector<FieldValue>&& value) {
281281
}
282282

283283
FieldValue FieldValue::ObjectValue(
284-
const std::map<const std::string, const FieldValue>& value) {
285-
std::map<const std::string, const FieldValue> copy(value);
284+
const std::map<std::string, FieldValue>& value) {
285+
std::map<std::string, FieldValue> copy(value);
286286
return ObjectValue(std::move(copy));
287287
}
288288

289-
FieldValue FieldValue::ObjectValue(
290-
std::map<const std::string, const FieldValue>&& value) {
289+
FieldValue FieldValue::ObjectValue(std::map<std::string, FieldValue>&& value) {
291290
FieldValue result;
292291
result.SwitchTo(Type::Object);
293292
std::swap(result.object_value_, value);
@@ -418,7 +417,7 @@ void FieldValue::SwitchTo(const Type type) {
418417
new (&array_value_) std::vector<FieldValue>();
419418
break;
420419
case Type::Object:
421-
new (&object_value_) std::map<const std::string, const FieldValue>();
420+
new (&object_value_) std::map<std::string, FieldValue>();
422421
break;
423422
default: {} // The other types where there is nothing to worry about.
424423
}

Firestore/core/src/firebase/firestore/model/field_value.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ class FieldValue {
111111
return string_value_;
112112
}
113113

114+
const std::map<std::string, FieldValue>& object_value() const {
115+
FIREBASE_ASSERT(tag_ == Type::Object);
116+
return object_value_;
117+
}
118+
114119
/** factory methods. */
115120
static const FieldValue& NullValue();
116121
static const FieldValue& TrueValue();
@@ -134,10 +139,8 @@ class FieldValue {
134139
static FieldValue GeoPointValue(const GeoPoint& value);
135140
static FieldValue ArrayValue(const std::vector<FieldValue>& value);
136141
static FieldValue ArrayValue(std::vector<FieldValue>&& value);
137-
static FieldValue ObjectValue(
138-
const std::map<const std::string, const FieldValue>& value);
139-
static FieldValue ObjectValue(
140-
std::map<const std::string, const FieldValue>&& value);
142+
static FieldValue ObjectValue(const std::map<std::string, FieldValue>& value);
143+
static FieldValue ObjectValue(std::map<std::string, FieldValue>&& value);
141144

142145
friend bool operator<(const FieldValue& lhs, const FieldValue& rhs);
143146

@@ -164,7 +167,7 @@ class FieldValue {
164167
firebase::firestore::model::ReferenceValue reference_value_;
165168
GeoPoint geo_point_value_;
166169
std::vector<FieldValue> array_value_;
167-
std::map<const std::string, const FieldValue> object_value_;
170+
std::map<std::string, FieldValue> object_value_;
168171
};
169172
};
170173

0 commit comments

Comments
 (0)