scan_netstring(3)

✨ scan_netstring β€” NAME πŸ’…

okay bestie so scan_netstring is literally the function that parses a netstring πŸŽ€ no cap, that's the whole vibe. it lives in the libowfat library, section 3 of the manual, and it's giving "quietly essential utility" energy fr fr πŸ¦‹


🌸 SYNTAX 🌸

here's how you summon it:

#include <libowfat/scan.h>

size_t scan_netstring(const char *in,size_t len,char** dest, size_t
*slen);

yeah that's the whole thing. five arguments, no drama, just vibes ✨


🫢 DESCRIPTION 🫢

so here's the tea: scan_netstring tries to parse the netstring sitting in your input buffer, which is (in,len) β€” like, the pointer in and the length len, that's your buffer, periodt.

if that buffer contains a valid netstring, then the pair (*dest,*slen) gets set to the start and length of the transported string. slay πŸ’–

but wait, important caveats, don't skip these bestie:

  • that string is not zero terminated. like, do not go treating it like a C string, i'm begging 😭
  • no copy is made. none. zero. scan_netstring just points *dest inside your input buffer, so it's a view not a clone πŸ‘‘ the way it just points into the original buffer is so efficient honestly, ate and left no crumbs.

⭐ RETURN VALUE ⭐

  • if parsing worked, you get the number of bytes in the netstring β€” and no, that's the outer representation, not the transported inner string, don't get it twisted πŸ™ˆ
  • if the input buffer did not contain a valid netstring (or a full one), you get 0. that's it. that's the signal πŸ’€

🌈 EXAMPLE 🌈

the raw memory buffer "foo" would become the netstring:

"3:foo,"

literally so simple, main character encoding behavior 🧚


πŸŽ€ SPEC πŸŽ€

the official spec lives right here:

http://cr.yp.to/proto/netstrings.txt

go read it, it's giving foundational literature πŸ“œβœ¨


πŸ’œ SEE ALSO πŸ’œ

  • fmt_netstring(3) β€” the other half of the duo, the making side to this parsing side πŸ”₯

and that's the page bestie! this one's from the Library Functions Manual, and it's scan_netstring(3) all the way down β€” same name up top, same name down bottom, iconic symmetry, we love a consistent queen πŸ‘‘πŸ’… πŸ¦‹