Comments (3)
Interesting point. Your suggestion is probably more robust in every possible way. I took the varargs approach for ease of use, but I guess I missed the obvious and important use case.
-- Normal, old style
local r1, r2, r2 = binser.deserailize(str)
-- Safe, new style
local success, results, len = pcall(binser.deserialize, str)
assert(success, results)
for i = 1, len do
print(results[i])
end
I will probably update the API to change this.
from binser.
I just pushed a change that should hopefully make use easier. binser.deserialize
now behaves exactly as your desired behavior. Surprisingly, I just had to change one line of code for that.
I also added a new form, deserializeN(str, n)
, which behaves much like the old form in that it unwraps the values for you. However, you have to pass your explicit maximum number to wrap in n. This hopefully resolves some ambiguity in the simple case, with the added benefit that we can now ignore values we don't need and not waste time parsing them. Nils can still be potentially ambiguous, though.
Unfortunately, this completely breaks the API. Let me know is this works for you, and you can close the issue.
from binser.
I think one nice idea could be something like local tbl, str = binser.deserialize(str, n)
which can be called multiple times to deserialize n
values from the string. Like the readme said, the data should be concatenable so deserializing should also be possible in parts similarly.
Not that I need this, but just something to think on if you want to try add features.
Yeah. Seems like the new changes do the job.
And API breaking is very unfortunate yes. Of course there could be different flavors of deserialization for different uses.
from binser.
Related Issues (19)
- Serialized types get mixed HOT 3
- Table duplicated HOT 18
- Add a version field HOT 1
- Error on malformed input when looking ahead HOT 10
- resource example HOT 2
- Lua 5.3 supported ? HOT 4
- readFile and writeFile do not return an error
- deserialing not have instruction HOT 1
- Is binser safe? HOT 1
- binser.unregister does not work. HOT 1
- float number bug in Lua5.4 HOT 2
- Tables not serializing with nested registered userdata. HOT 5
- deserialize Registerd Class example ? HOT 2
- Library not working in 5.3 version due to deprecated math functions HOT 7
- Update deserialize/N doc HOT 1
- Having some trouble deserializing a third-party class
- Priting a serialized table gives unicode symbols HOT 1
- fairly simple issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from binser.