Comments (4)
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.
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.
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.
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)
- thorough unit tests for `cobs_decode`
- encode API overhaul: incremental encoding HOT 1
- Unsigned integer underflow HOT 2
- invalid frame case for cobs_inplace_decode HOT 4
- Rewrite `cobs_encode_inc` to support small buffers
- Incremental decoder
- Update docs to new `cobs_decode_inc` and `cobs_encode_inc` functions
- SPDX License headers 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 nanocobs.