Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++] Fix base to derived deserialization #745

Merged
merged 5 commits into from
Dec 11, 2017

Conversation

ara-ayvazyan
Copy link
Contributor

@ara-ayvazyan ara-ayvazyan commented Dec 8, 2017

With this change deserialization will now fail by throwing bond::CoreException when BT_STOP is encountered while deserializing a base struct.

Fixes #742

@@ -388,6 +388,12 @@ class RequiredFieldValiadator
_required = next_required_field<typename schema<T>::type::fields>::value;
}

void Base(bool done) const
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this is a breaking change. Not sure if this needs to be mentioned in changelog.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this should be mentioned in the change log.

CHANGELOG.md Outdated
@@ -48,6 +48,8 @@ different versioning scheme, following the Haskell community's
* gRPC v1.7.1 is now required to use Bond-over-gRPC.
* Fixed includes for gRPC services with events or parameterless methods.
[Issue #735](https://github.com/Microsoft/bond/issues/735)
* Fixed a bug which would read unrelated struct's field(s) when deserializing base struct
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: a few words missing "...would read an unrelated struct's... deserializing a base struct." and move the period to the end of this sentence have have the "Issue #742" float at the end.

@@ -388,6 +388,12 @@ class RequiredFieldValiadator
_required = next_required_field<typename schema<T>::type::fields>::value;
}

void Base(bool done) const
{
if (done)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: slight preference for curly braces always.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was trying to be consistent here.

mutable uint16_t _required;
};

template <typename T>
void RequiredFieldValiadator<T>::MissingFieldException() const
{
(void)typename schema<T>::type();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to construct an instance of the field?

Copy link
Contributor Author

@ara-ayvazyan ara-ayvazyan Dec 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To force-instantiate a possibly template static data member metadata (see this link error, even though it happens for the newly added exception function, but the issue is the same).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we comment the line?

(void)typename schema<T>::type();

BOND_THROW(CoreException,
"De-serialization failed: unexpected struct stop is encountered for "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: "unexpected struct stop encountered for..."

@@ -388,6 +388,12 @@ class RequiredFieldValiadator
_required = next_required_field<typename schema<T>::type::fields>::value;
}

void Base(bool done) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels confusing to be doing this in something called "RequiredFieldValidator", as this doesn't have to do with required fields.

Should/can this be in To directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case the user will not be able to customize that behavior. If we treat this as an incorrect payload detection, then I guess should be OK to move it to To<T> transform.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine having this apply to all cases of deserialization and not be customizable. This is about detecting an invalid payload/bad downcast.

To keep it customizable, we could have a different validator that composes with RFV. PayloadIsntBeingDowncastIncorrectlyValidator<T> : T or something.

@chwarr chwarr merged commit 9ca99d4 into microsoft:master Dec 11, 2017
@ara-ayvazyan ara-ayvazyan deleted the fix_base_deserialize branch December 11, 2017 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants