Giter VIP home page Giter VIP logo

Comments (4)

charlesnicholson avatar charlesnicholson commented on May 30, 2024

Ah, the _inplace decode and encode are only guaranteed to work if the entire payload is <= COBS_INPLACE_SAFE_BUFFER_SIZE which you'll see is small. _inplace encoding is more interesting, because it's an optimization that guarantees you don't need an extra buffer. The big difference with the _inplace API is that it lets you encode in-place, which is possible only with very constrained payloads. cobs_decode_inplace is there for parity.

If you're only looking at decoding, and you have a 10,000 byte encoded buffer, you can still decode it "in-place" by simply calling cobs_decode with the out_dec and enc pointers pointing to the same address: byte 0 of the encoded buffer.

As I type this up I realize the naming conventions aren't great, sorry about that. I'll brainstorm better names, also if you have any suggestions I'm all ears :)

from nanocobs.

charlesnicholson avatar charlesnicholson commented on May 30, 2024

An example:

char buf[16384];
unsigned encoded_len;
fill_buf_width_cobs_encoded_data(buf, &encoded_len); // your function
unsigned decoded_len;
cobs_decode(buf, encoded_len, buf, sizeof(buf), &decoded_len);
// at this point,  "buf" will contain the decoded payload, and "decoded_len" is the length of the decoded payload.

Is this what you're looking to achieve?

from nanocobs.

redfast00 avatar redfast00 commented on May 30, 2024

Yes, thank you! Was indeed a bit confused that the cobs_decode also decodes inplace (but to your defense, this is mentioned in the README, I just overlooked it)

from nanocobs.

charlesnicholson avatar charlesnicholson commented on May 30, 2024

Glad it does what you want! I'll update the docs and try to think of better names for the _inplace versions; it's clearly a soft spot in the API.

from nanocobs.

Related Issues (9)

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.