aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core/src/firebase/firestore/nanopb
diff options
context:
space:
mode:
authorGravatar rsgowman <rgowman@google.com>2018-05-15 17:02:08 -0400
committerGravatar GitHub <noreply@github.com>2018-05-15 17:02:08 -0400
commit520a0c0a84c34897aae10564ed48ec3efc508fbf (patch)
treeaaab4065909619e87d8f798916fe747c9c022a33 /Firestore/core/src/firebase/firestore/nanopb
parentc555778bcfd77a9644f65c00b2b2cf516f4f08d1 (diff)
[De]serialize empty Document instances (#1262)
* [De]serialize empty Document instances Still TODO: - non-empty - NoDocument - ErrorHandling
Diffstat (limited to 'Firestore/core/src/firebase/firestore/nanopb')
-rw-r--r--Firestore/core/src/firebase/firestore/nanopb/reader.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.h b/Firestore/core/src/firebase/firestore/nanopb/reader.h
index 7d77a4d..093e20b 100644
--- a/Firestore/core/src/firebase/firestore/nanopb/reader.h
+++ b/Firestore/core/src/firebase/firestore/nanopb/reader.h
@@ -80,6 +80,11 @@ class Reader {
*
* Call this method when reading a nested message. Provide a function to read
* the message itself.
+ *
+ * @param read_message_fn Function to read the submessage. Note that this
+ * function is expected to check the Reader's status (via
+ * Reader::status().ok()) and if not ok, to return a placeholder/invalid
+ * value.
*/
template <typename T>
T ReadNestedMessage(const std::function<T(Reader*)>& read_message_fn);
@@ -130,14 +135,14 @@ T Reader::ReadNestedMessage(const std::function<T(Reader*)>& read_message_fn) {
// Implementation note: This is roughly modeled on pb_decode_delimited,
// adjusted to account for the oneof in FieldValue.
- if (!status_.ok()) return T();
+ if (!status_.ok()) return read_message_fn(this);
pb_istream_t raw_substream;
if (!pb_make_string_substream(&stream_, &raw_substream)) {
status_ =
util::Status(FirestoreErrorCode::DataLoss, PB_GET_ERROR(&stream_));
pb_close_string_substream(&stream_, &raw_substream);
- return T();
+ return read_message_fn(this);
}
Reader substream(raw_substream);