Live data from Hacker News

Netstrings (1997)

cr.yp.to

21–30 of 30 posts

Re: Netstrings (1997)

#21
Another string length O(1) encoding format like Pascal strings that were len (unsigned byte) + data. Limited to 255 characters however.

Dollar, NUL, and other terminated strings, by contrast, are string length O(N).

Re: Netstrings (1997)

#22
So much of the terse, utilitarian, DJB Way was overpowered by bloated corporate crap 8-/

One still functional example exists in voidlinux's init system.

There was never any need for systemd 8-/

Except leveraging RedHat/IBM's domination of the linux user space ecosystem...

Re: Netstrings (1997)

#23

Another string length O(1) encoding format like Pascal strings that were len (unsigned byte) + data. Limited to 255 characters however. Dollar, NUL, and other terminated strings, by contrast, are string length O(N).

fast cgi has a good one, length then binary follows, if the length is 127 or less, the length is contained within one byte, if not the length is contained in 4 bytes, then the data follows. Midi has a similar scheme for representing some numbers, the high order bit denotes if there's another byte of the number following or something like that lol

Re: Netstrings (1997)

#24

if (scanf("%9lu",&len) 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) Ah, the wonders of error-handling in C. Also, I wonder what's wrong with buf = malloc(len ? len : 1);

Or even: if (len == 0) return null_buffer_singleton; /* special shared representation for 0: */

Because then the caller needs to treat it differently from non-empty buffers.

Re: Netstrings (1997)

#25

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.

It's mathematically impossible to describe an arbitrary length in a fixed length.

Re: Netstrings (1997)

#26

Another string length O(1) encoding format like Pascal strings that were len (unsigned byte) + data. Limited to 255 characters however. Dollar, NUL, and other terminated strings, by contrast, are string length O(N).

strlen for netstring is O(log n).

Re: Netstrings (1997)

#27
post #24

Earlier quoted context omitted.

Or even: if (len == 0) return null_buffer_singleton; /* special shared representation for 0: */

Because then the caller needs to treat it differently from non-empty buffers.

No, it doesn't. It calls:

  void buffer_free(void *buf)
  {
     if (buf != null_buffer_singleton)
       free(buf);
  }

Re: Netstrings (1997)

#28
post #24

Earlier quoted context omitted.

Because then the caller needs to treat it differently from non-empty buffers.

No, it doesn't. It calls: void buffer_free(void *buf) { if (buf != null_buffer_singleton) free(buf); }

...which treats it differently from non-empty buffers :)

But frankly, having a 1-byte buffer, pointer to which can serve as a sentinel value à la NULL (but dereferenceable!), and which you can pass to free() without it being deallocated is indeed rather useful.

Re: Netstrings (1997)

#29
post #25

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.

It's mathematically impossible to describe an arbitrary length in a fixed length.

Luckily in math we do not have to allocate memory and worry about buffer overflows.

Re: Netstrings (1997)

#30

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.

Or you could just have the standard have a "Conformance Limits" section where it says something similar to "Every implementation shall support a length field value of at least 9223372036854775807, with an unlimited number of leading zeros". In other words, values beyond that are not forbidden by the spec, but are outside of the conformance requirements. It is a quality of implementation issue whether a given implemen…

That the spec is lenient and the conformance test strict makes ot only worse.
Post reply on HN