Why do we send the length of a string in most of the currently protocols

107 Views Asked by At

I wondering why most of the protocols (Like dns for example) write the length of a string before it.

For example:

3www6google3com

Why did it do this in that way? I can't figure out through searches over the internet.

1

There are 1 best solutions below

0
On BEST ANSWER

Because that way we don't limit what can be in the string. The alternative is to use some sort of in-band signaling of the end of the string, like C's \0, which either means you can't have some kinds of data in it, or that you have to deal with quoting of some sort. Prefix lengths are much easier to work with and less error-prone.