diff options
author | rsgowman <rgowman@google.com> | 2018-06-04 15:31:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-04 15:31:10 -0400 |
commit | 26b8ac9ee43bb67b08e4bc62af98ac6bda2f121c (patch) | |
tree | bf6b194b8a4a6247247a22b701a65e2be1eaf723 /Firestore/core/src/firebase/firestore/nanopb | |
parent | a135ee17175f8f186e73252263b8dbc3785f3d3c (diff) |
Skip unknown fields while decoding FieldValue proto objects. (#1354)
Diffstat (limited to 'Firestore/core/src/firebase/firestore/nanopb')
-rw-r--r-- | Firestore/core/src/firebase/firestore/nanopb/reader.cc | 8 | ||||
-rw-r--r-- | Firestore/core/src/firebase/firestore/nanopb/reader.h | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.cc b/Firestore/core/src/firebase/firestore/nanopb/reader.cc index ec4282d..69e3d83 100644 --- a/Firestore/core/src/firebase/firestore/nanopb/reader.cc +++ b/Firestore/core/src/firebase/firestore/nanopb/reader.cc @@ -136,6 +136,14 @@ std::string Reader::ReadString() { return result; } +void Reader::SkipField(const Tag& tag) { + if (!status_.ok()) return; + + if (!pb_skip_field(&stream_, tag.wire_type)) { + status_ = Status(FirestoreErrorCode::DataLoss, PB_GET_ERROR(&stream_)); + } +} + } // namespace nanopb } // namespace firestore } // namespace firebase diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.h b/Firestore/core/src/firebase/firestore/nanopb/reader.h index 930211a..2c16ec4 100644 --- a/Firestore/core/src/firebase/firestore/nanopb/reader.h +++ b/Firestore/core/src/firebase/firestore/nanopb/reader.h @@ -89,6 +89,15 @@ class Reader { template <typename T> T ReadNestedMessage(const std::function<T(Reader*)>& read_message_fn); + /** + * Discards the bytes associated with the given tag. + * + * @param tag The tag associated with the field that is otherwise about to be + * read. This method uses the tag to determine how many bytes should be + * discarded. + */ + void SkipField(const Tag& tag); + size_t bytes_left() const { return stream_.bytes_left; } |