From 47ab39aee6330f59263b0a9b2fc36536544651fd Mon Sep 17 00:00:00 2001 From: rsgowman Date: Mon, 25 Jun 2018 10:06:35 -0400 Subject: Refactor nanopb decoding methods (#1438) Rather than decoding the type, and then the contents, decode them both at once. --- .../firebase/firestore/local/local_serializer.cc | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'Firestore/core/src/firebase/firestore/local') 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 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 LocalSerializer::DecodeMaybeDocument( [&](Reader* reader) -> std::unique_ptr { 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 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); -- cgit v1.2.3