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

[Suggestion] Option to parse symbols as objects #9

Open
sancarn opened this issue Sep 8, 2018 · 4 comments
Open

[Suggestion] Option to parse symbols as objects #9

sancarn opened this issue Sep 8, 2018 · 4 comments

Comments

@sancarn
Copy link

sancarn commented Sep 8, 2018

If I have the following code:

p = Base64.encode64(Marshal.dump(:a))
p = Base64.encode64(Marshal.dump("a"))

I get:

"BAg6BmE=\n"
"BAhJIgZhBjoGRVQ=\n"

If I try to parse these with marshal:

var _symbol = (new Marshal("BAg6BmE=\n",'base64')).parsed
var _string = (new Marshal("BAhJIgZhBjoGRVQ=\n",'base64')).parsed
console.log(_symbol == _string)

I get: True

Is there any way to extend the Marshal parsing algorithm to parse symbols as JavaScript symbols instead?

@clayzermk1
Copy link
Owner

When this was first written ES6 certainly wasn't as supported as it is now. Nowadays it would make sense to translate a Ruby symbol as a JS symbol.

I'm certainly open to a PR if you'd like to take a stab at it.

@clayzermk1
Copy link
Owner

clayzermk1 commented Sep 10, 2018

JSON doesn't support symbols, so a patch will probably also need to take that into consideration and modify the toJSON() function.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior

@sancarn
Copy link
Author

sancarn commented Sep 11, 2018

I'll take a look at it. Though the Marshal binary structure seems super random... xD

Otherwise I'll likely build my own parser from RubyObj.inspect

@sancarn
Copy link
Author

sancarn commented Sep 16, 2018

I didn't get very far with extending the marshaller, so decided to just build my own ruby object parser in javascript: RON.js

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

No branches or pull requests

2 participants