From 520a0c0a84c34897aae10564ed48ec3efc508fbf Mon Sep 17 00:00:00 2001 From: rsgowman Date: Tue, 15 May 2018 17:02:08 -0400 Subject: [De]serialize empty Document instances (#1262) * [De]serialize empty Document instances Still TODO: - non-empty - NoDocument - ErrorHandling --- Firestore/core/src/firebase/firestore/nanopb/reader.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Firestore/core/src/firebase/firestore/nanopb') 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 T ReadNestedMessage(const std::function& read_message_fn); @@ -130,14 +135,14 @@ T Reader::ReadNestedMessage(const std::function& 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); -- cgit v1.2.3