aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core/src/firebase/firestore/local
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/local
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/local')
-rw-r--r--Firestore/core/src/firebase/firestore/local/local_serializer.cc24
1 files changed, 6 insertions, 18 deletions
diff --git a/Firestore/core/src/firebase/firestore/local/local_serializer.cc b/Firestore/core/src/firebase/firestore/local/local_serializer.cc
index fea99fb..d8e039b 100644
--- a/Firestore/core/src/firebase/firestore/local/local_serializer.cc
+++ b/Firestore/core/src/firebase/firestore/local/local_serializer.cc
@@ -84,25 +84,8 @@ std::unique_ptr<model::MaybeDocument> LocalSerializer::DecodeMaybeDocument(
// Ensure the tag matches the wire type
switch (tag.field_number) {
case firestore_client_MaybeDocument_document_tag:
- case firestore_client_MaybeDocument_no_document_tag:
- if (tag.wire_type != PB_WT_STRING) {
- reader->set_status(
- Status(FirestoreErrorCode::DataLoss,
- "Input proto bytes cannot be parsed (mismatch between "
- "the wiretype and the field number (tag))"));
- return nullptr;
- }
- break;
-
- default:
- // Unknown tag. According to the proto spec, we need to ignore these. No
- // action required here, though we'll need to skip the relevant bytes
- // below.
- break;
- }
+ if (!reader->RequireWireType(PB_WT_STRING, tag)) return nullptr;
- switch (tag.field_number) {
- case firestore_client_MaybeDocument_document_tag:
// 'no_document' and 'document' are part of a oneof. The proto docs
// claim that if both are set on the wire, the last one wins.
no_document = nullptr;
@@ -113,9 +96,12 @@ std::unique_ptr<model::MaybeDocument> LocalSerializer::DecodeMaybeDocument(
[&](Reader* reader) -> std::unique_ptr<model::Document> {
return rpc_serializer_.DecodeDocument(reader);
});
+
break;
case firestore_client_MaybeDocument_no_document_tag:
+ if (!reader->RequireWireType(PB_WT_STRING, tag)) return nullptr;
+
// 'no_document' and 'document' are part of a oneof. The proto docs
// claim that if both are set on the wire, the last one wins.
document = nullptr;
@@ -123,6 +109,8 @@ std::unique_ptr<model::MaybeDocument> LocalSerializer::DecodeMaybeDocument(
// TODO(rsgowman): Parse the no_document field.
abort();
+ break;
+
default:
// Unknown tag. According to the proto spec, we need to ignore these.
reader->SkipField(tag);