Commits


rsgowman authored and GitHub committed 786f7666f95
Refactor serializers (#1625) * Use nanopb::Reader, Writer, in the serializer's public methods. This eliminates overloads that take raw bytes. * Refactor the serializer's return values from Status, StatusOr<T> to void, optional<T> (or unique_ptr<T>) for encoding/decode methods, respectively. * Errors during serializer encoding methods now fatal. Previously, we'd propagate the errors back to the caller, but there aren't any errors that could realistically be recovered from. So now we just abort(). (This is in contrast to *de*coding methods, which could generate errors that we might want to recover from.) * Reduce early returns in the serializers * Unify public/private method return values of the serializers. Now the private methods return void/optional, just like the public methods. * Reader::ReadTag now tracks the last read tag. This allows: * RequireWireType to not need it as a parameter * SkipField to not need it as a parameter * ReadTag to be inlined into most switch statements * Move RequireWireType into ReadX methods * Reader::SkipField -> Reader::SkipUnknown * Add ReadNestedMessage overload in order to accept non-static functions. * Add a few using statements to simplify code. (Also keeps local serializer more in sync with the remote serializer.) * Use nullopt/nullptr instead of {} * Reader::update_status() -> Fail() * Add DecodeSnapshotVersion * Don't directly update status within nanopb::Reader. Instead, call Reader::Fail() (which calls Status::Update()). This ensures we don't accidentally overwrite the first error status with a subsequent one.