xHasKx / luamqtt

luamqtt - Pure-lua MQTT v3.1.1 and v5.0 client
https://xhaskx.github.io/luamqtt/
MIT License
154 stars 41 forks source link

64 bits support required? #17

Closed rluitwieler closed 4 years ago

rluitwieler commented 4 years ago

Compliments for this nice project!

I'm currently experimenting with it, but my lua environment is version 5.2 and cannot use LuaBitOp (or any other dynamic binding). Looking at the code, I suspect 32 bits support may be sufficient and I ported all of it to my framework simply using the bit32 functions; all unittests are succeeding.

Am I right about my suspicion or am I missing something?

xHasKx commented 4 years ago

Hi @rluitwieler ,

Compliments for this nice project!

Thanks!

I suspect 32 bits support may be sufficient

You are correct, the MQTT protocol v3.1.1 and v5 require to write/parse the numeric values which always fit into the uint32_t type.

Actually I think it'll be a good idea to get rid of a BitOp library dependency in favor of pure mathematical calculations of bit operations. Anyway, it might be an option passed when loading the mqtt module in Lua. One of the main ideas of this library is almost zero-dependency.

Did you implement all required bit-operations in pure Lua code? In this case can you share this code?

rluitwieler commented 4 years ago

Hey @xHasKx ,

You are correct, the MQTT protocol v3.1.1 and v5 require to write/parse the numeric values which always fit into the uint32_t type.

That's great!

Actually I think it'll be a good idea to get rid of a BitOp library dependency in favor of pure mathematical calculations of bit operations. Anyway, it might be an option passed when loading the mqtt module in Lua. One of the main ideas of this library is almost zero-dependency.

I agree, but there are some sidenotes you'll have to think/decide on. I used the bit32 module which is only available by default in Lua 5.2. Furthermore, in some implementations of that module the underlying data type is a signed 32 bits integer, so this adds an extra dependency in return on the implementation (but if I am correct, this only pertains to 32 bits operating systems). See for instance http://lua-users.org/wiki/BitwiseOperators .

Did you implement all required bit-operations in pure Lua code? In this case can you share this code?

As you may understand by now, I did not implement those myself, but simply changed one line in bitwrap.lua to return the bit32 table.

xHasKx commented 4 years ago

Now I get this. I've missed that Lua 5.2 has the standard bit32 module.

Furthermore, in some implementations of that module the underlying data type is a signed 32 bits integer, so this adds an extra dependency in return on the implementation (but if I am correct, this only pertains to 32 bits operating systems). See for instance http://lua-users.org/wiki/BitwiseOperators .

According to the official module documentation ( https://www.lua.org/manual/5.2/manual.html#6.7 ), "all results are in the range [0, 2^32 - 1]". I hope all Lua 5.2 implementations will follow this rule. I've also checked it's true on 32-bit Ubuntu.

So I'll use the bit32 module on Lua 5.2 in the bitwrap.lua. I hope to publish a new version this week.

Thanks for your valuable notes, @rluitwieler !

xHasKx commented 4 years ago

@rluitwieler, I've posted a new version. Thanks again!

rluitwieler commented 4 years ago

@xHasKx , you are welcome and you are right: upon closer inspection, the link I mentioned pertains mostly to alternatives for Lua 5.1. So for Lua 5.2 we should be in the clear.