aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core/src/firebase/firestore/nanopb
diff options
context:
space:
mode:
authorGravatar rsgowman <rgowman@google.com>2018-06-25 10:06:35 -0400
committerGravatar GitHub <noreply@github.com>2018-06-25 10:06:35 -0400
commit47ab39aee6330f59263b0a9b2fc36536544651fd (patch)
treeefff1d390bc56c7a7d00628da6d81dca377684be /Firestore/core/src/firebase/firestore/nanopb
parent137ce37363d72ac1d643ea9f93bc6e6665367e57 (diff)
Refactor nanopb decoding methods (#1438)
Rather than decoding the type, and then the contents, decode them both at once.
Diffstat (limited to 'Firestore/core/src/firebase/firestore/nanopb')
-rw-r--r--Firestore/core/src/firebase/firestore/nanopb/reader.cc11
-rw-r--r--Firestore/core/src/firebase/firestore/nanopb/reader.h10
2 files changed, 21 insertions, 0 deletions
diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.cc b/Firestore/core/src/firebase/firestore/nanopb/reader.cc
index 3b102f0..3e6d92e 100644
--- a/Firestore/core/src/firebase/firestore/nanopb/reader.cc
+++ b/Firestore/core/src/firebase/firestore/nanopb/reader.cc
@@ -46,6 +46,17 @@ Tag Reader::ReadTag() {
return tag;
}
+bool Reader::RequireWireType(pb_wire_type_t wire_type, Tag tag) {
+ if (!status_.ok()) return false;
+ if (wire_type != tag.wire_type) {
+ set_status(Status(FirestoreErrorCode::DataLoss,
+ "Input proto bytes cannot be parsed (mismatch between "
+ "the wiretype and the field number (tag))"));
+ return false;
+ }
+ return true;
+}
+
void Reader::ReadNanopbMessage(const pb_field_t fields[], void* dest_struct) {
if (!status_.ok()) return;
diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.h b/Firestore/core/src/firebase/firestore/nanopb/reader.h
index 7dd7432..76dc3b6 100644
--- a/Firestore/core/src/firebase/firestore/nanopb/reader.h
+++ b/Firestore/core/src/firebase/firestore/nanopb/reader.h
@@ -58,6 +58,16 @@ class Reader {
Tag ReadTag();
/**
+ * Ensures the specified tag is of the specified type. If not, then
+ * Reader::status() will return a non-ok value (with the code set to
+ * FirestoreErrorCode::DataLoss).
+ *
+ * @return Convenience indicator for success. (If false, then status() will
+ * return a non-ok value.)
+ */
+ bool RequireWireType(pb_wire_type_t wire_type, Tag tag);
+
+ /**
* Reads a nanopb message from the input stream.
*
* This essentially wraps calls to nanopb's pb_decode() method. If we didn't