Skip to content

Let the shim functions return an error #67

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

Closed
zond opened this issue Mar 28, 2015 · 11 comments
Closed

Let the shim functions return an error #67

zond opened this issue Mar 28, 2015 · 11 comments
Labels

Comments

@zond
Copy link

zond commented Mar 28, 2015

At least the decode implementation usually has a few error cases, and it would be nice if those errors could be properly propagated.

@philhofer
Copy link
Member

Agreed

@zond
Copy link
Author

zond commented Mar 30, 2015

Do you want me to start hammering out a pull request, or will you do this? :)

@philhofer
Copy link
Member

I probably won't have time to look at this until later this week. Pull requests more than welcome.

@zond
Copy link
Author

zond commented Mar 30, 2015

I will try to take a look at it the next few days.

Any pointers on where to look?

@philhofer
Copy link
Member

The rabbit hole starts here.

You'll also want to look at gen.BaseElem and its respective printing functions in gen/encode.go, gen/decode.go, gen/marshal.go, etc.

@philhofer
Copy link
Member

It may make sense to implement this as a different directive. It may be tough to preserve backwards-compatibility otherwise.

@zond
Copy link
Author

zond commented Apr 1, 2015

I just ran out of time after fixing a bug in one of my projects, and then trying out your appengine build tag stuff. I will try to look at this during the weekend.

@shabbyrobe
Copy link
Contributor

@philhofer, would you be happy for me to pick this up? I really need this functionality too and I'm happy to do the work. Agree it should be a different directive.

@philhofer
Copy link
Member

philhofer commented Jul 5, 2017 via email

shabbyrobe added a commit to shabbyrobe/msgp that referenced this issue Jul 16, 2017
@shabbyrobe
Copy link
Contributor

shabbyrobe commented Jul 16, 2017

OK I have a first pass of this, some feedback would be great! Ended up adding an optional extra argument to the directive instead of a new directive. The zero value defaults to the existing behaviour:

//existing behaviour is default:
//msgp:shim MyType as:string using:fromMyType/toMyType

//explicit declaration of existing behaviour:
//msgp:shim MyType as:string using:fromMyType/toMyType mode:cast

//new mode:
//msgp:shim MyType as:string using:fromMyType/toMyType mode:convert

I ran into some sticky stuff with the size calculations. These shim functions could be doing all kinds of different stuff under the hood so it seems like it may be a performance tradeoff between running the shim function twice to get an accurate size or running it once and guessing the size, even if that guess will almost certainly be wrong in the case where the base type is a string. Either that or I'm missing something about how to do it more effectively... there's a good chance of that.

"Convert" might be a less than ideal name for it too as there is already a member on BaseElem called Convert, but I couldn't think of something better at the time.

@shabbyrobe
Copy link
Contributor

Reckon we can close this one off or does it still need a bit more work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants