logoalt Hacker News

Netstrings (1997)

22 pointsby signa11today at 5:33 AM10 commentsview on HN

Comments

weinzierltoday at 10:41 AM

Making the thing that describes the bounds of an arbitrary length thing itself arbitrary length sound like an unnecessarily risky complication to me.

Especially since it only grows with the log of the thing it bounds. So, we could easily have s fixed length length field that covers all ever possible length values.

regularfrytoday at 6:29 AM

Tagged Netstrings (tnetstrings) was a related proposal from 15 years ago or so. It replaces the comma with a single-character type definition so you can do JSON-like objects with a couple of recursive types: you had ',', '#', '^', '!', and '~' for strings, integers, floats, booleans, and nulls, then ']' and '}' for lists and dictionaries.

Most of the links have bitrotted and I don't think it ever got much traction, but I did always like how simple it was. There's a copy someone grabbed of the original spec here: https://raw.githubusercontent.com/ged/tnetstrings.info/refs/...

show 1 reply
Joker_vDtoday at 9:06 AM

    if (scanf("%9lu",&len) < 1) barf();  /* >999999999 bytes is bad */
    if (getchar() != ':') barf();
    buf = malloc(len + 1);       /* malloc(0) is not portable */
    if (!buf) barf();
    if (fread(buf,1,len,stdin) < len) barf();
    if (getchar() != ',') barf();
Ah, the wonders of error-handling in C. Also, I wonder what's wrong with

    buf = malloc(len ? len : 1);
show 1 reply
ocrowtoday at 6:10 AM

Seems like a coherent, sensible proposal, as one might expect from djb. Any notable protocols use them?

show 5 replies
gnabgibtoday at 5:36 AM

(1997) -DJB