Giter Club home page Giter Club logo

Comments (3)

bakpakin avatar bakpakin commented on July 17, 2024

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.

bakpakin avatar bakpakin commented on July 17, 2024

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.

Rochet2 avatar Rochet2 commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.