Skip to content

get_double() asserting on valid input #22

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
gooderist opened this issue Jun 8, 2015 · 8 comments
Closed

get_double() asserting on valid input #22

gooderist opened this issue Jun 8, 2015 · 8 comments

Comments

@gooderist
Copy link

Hello, I am seeing get_double() asserting on sio_message.h: 48 when I send in an object with either an integer or value like "5.0".

I guess while I'm at it I'll also request that something be done to prevent the assert on get_int() when a double is provided, like rounding or truncation?

@melode11
Copy link
Contributor

melode11 commented Jun 8, 2015

Can you paste some piece of code?

@gooderist
Copy link
Author

On the node server side I am sending in

maoSocket.emit 'play', {file: "#{__dirname}/8sec.mp3", offset: 5.0}

Then on the receiving end

        h.socket()->on("play", socket::event_listener([&](event& event){
            message::ptr const& m = event.get_message();
            map<string, message::ptr> eventObject;
            String filename;
            double offset = -1;
            if (m->get_map().find("file") != m->get_map().end())
                filename = m->get_map()["file"]->get_string();
            if (m->get_map().find("offset") != m->get_map().end())
                offset = m->get_map()["offset"]->get_double(); // <- Asserts here unless I use get_int()
            if (m->get_map().find("event") != m->get_map().end())
                eventObject = m->get_map()["event"]->get_map();
            playFile(filename, eventObject, offset);
        }));

Thanks!

@melode11
Copy link
Contributor

Can you look at the actual transmitting json,I think it converted 5.0 to 5. So offset was interpreted as integer by client.

@melode11
Copy link
Contributor

You have had a common case. I'll think about providing generic accessors for number types.

@gooderist
Copy link
Author

Thanks, I'm pretty sure the conversion from 5.0 to 5 is the culprit. But since all javascript numbers are doubles wouldn't it make sense to make get_double() always be valid on numerical values? Otherwise, we'd have to add a fractional like 0.00001 to any n.0 value before sending it in and then subtract it out on the client side. Thanks again.

@melode11
Copy link
Contributor

@oh3netid Yes, your're right.

@melode11
Copy link
Contributor

try tag 1.5.0

@gooderist
Copy link
Author

Works great! Thank you.

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

No branches or pull requests

2 participants