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

bson.to_double overlooked? #1

Open
josefnpat opened this issue Apr 4, 2013 · 5 comments
Open

bson.to_double overlooked? #1

josefnpat opened this issue Apr 4, 2013 · 5 comments

Comments

@josefnpat
Copy link

It seems that double values don't work! I don't see function bson.to_double defined anywhere.

https://github.com/tcoram/bson-lua/blob/master/bson.lua#L81

Any chance you can clean this up, as I am not familiar with the bson spec sheet.

Error: bson.lua:81: attempt to call field 'to_double' (a nil value) 
@tcoram
Copy link
Owner

tcoram commented Apr 4, 2013

Not so much as overlooked as (currently) avoided. I've yet to find an (easy) way to coerce Lua to encode/decode little endian ordered doubles. I left the function undefined so there is no ambiguity as to what will happen when you try to encode a double.

@daurnimator
Copy link

Have a look at my code at https://github.com/daurnimator/mongol/blob/master/mongol/ll.lua which is what most people end up using

@tcoram
Copy link
Owner

tcoram commented Jul 16, 2013

Clever :)
I've resisted luaJIT/ffi because I wanted to keep the implementation pure (I've got some embedded hosts I'm using), but I never thought of exploiting the Lua bytecode!

However, this approach would be a problem with big-endian machines, wouldn't it? Hmm... BSON specifies little-endian encoding and I guess just about all modern CPUs are little endian these days (ARM defaults to this, Intel, etc), so it should be portable most everywhere...

Mind if I incorporate your technique?

@daurnimator
Copy link

sure/go for it.

IEEE754 floating point numbers do not have an endianess.

FWIW you can steal any of the code I wrote here: https://github.com/daurnimator/mongol/blob/master/mongol/bson.lua

For the record, I abandoned mongo/bson when I realise that bson "dictionarys" are ordered; i.e. they are an ordered array of key/value pairs, and can't actually represent a hash.

@tcoram
Copy link
Owner

tcoram commented Jul 16, 2013

IEEE754 floating point numbers do not have an endianess.

Yes. Of course. Duh on my part.

For the record, I abandoned mongo/bson when I realise that bson "dictionarys" are ordered;

Hmm... the spec doesn't exactly make that obvious, but I do see some rather vocal replies (that, "of course", it is ordered) on the mailing list.

I don't use mongo. I use bson as a less verbose json for some simple payload encoding (where the doc is picked apart via hash indexes).

Thanks for pointing that out though.

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

3 participants