Consider changing 'pb' to an instance #222
Replies: 2 comments 4 replies
-
You could use multiple state to implement this: local oldstate = pb.state(nil) -- fetch the old, and make a new instead
local newstate = pb.state() -- now you can fetch the new state
-- use it:
protoc.reload()
-- restore the old state
pb.state(oldstate)
-- or use the new state instead
pb.state(newstate) The reason to make API this way is for compatible with earlier intreface :-( |
Beta Was this translation helpful? Give feedback.
-
Thank you for your suggestion, but I am concerned that the extra overhead with swapping states may make the code too slow. I may have to process Sparkplug MQTT messages at a high rate. Please consider the following backward compatible solution for future releases: Move the existing C code into a new module named "pbuf". |
Beta Was this translation helpful? Give feedback.
-
Thank you for providing this Lua module. I have tested your implementation with MQTT Sparkplug
https://www.eclipse.org/tahu/spec/Sparkplug%20Topic%20Namespace%20and%20State%20ManagementV2.2-with%20appendix%20B%20format%20-%20Eclipse.pdf
Your code can compile, encode, and decode Sparkplug B Google Protocol Buffer Schema and messages.
Having said that, I noticed something unusual in your implementation. The pb module is not designed as a Lua userdata object and modifications to pb is directly in the global environment. That means in a large application, everyone work on the same instance, which can make it difficult to use. For example, one module may call pb.clear() and invalidate for all users of the module.
I propose that the code instead is change to work as follows:
From:
local pb = require "pb"
pb.load(data)
To:
local pb = require "pb".new()
pb:load(data)
Beta Was this translation helpful? Give feedback.
All reactions