<s>
In	O
computer	B-General_Concept
programming	I-General_Concept
,	O
a	O
netstring	B-Protocol
is	O
a	O
formatting	O
method	O
for	O
byte	O
strings	O
that	O
uses	O
a	O
declarative	O
notation	O
to	O
indicate	O
the	O
size	O
of	O
the	O
string	O
.	O
</s>
<s>
Netstrings	B-Protocol
store	O
the	O
byte	O
length	O
of	O
the	O
data	O
that	O
follows	O
,	O
making	O
it	O
easier	O
to	O
unambiguously	O
pass	O
text	O
and	O
byte	O
data	O
between	O
programs	O
that	O
could	O
be	O
sensitive	O
to	O
values	O
that	O
could	O
be	O
interpreted	O
as	O
delimiters	B-Algorithm
or	O
terminators	O
(	O
such	O
as	O
a	O
null	O
character	O
)	O
.	O
</s>
<s>
The	O
comma	O
makes	O
it	O
slightly	O
simpler	O
for	O
humans	O
to	O
read	O
netstrings	B-Protocol
that	O
are	O
used	O
as	O
adjacent	O
records	O
,	O
and	O
provides	O
weak	O
verification	O
of	O
correct	O
parsing	B-Language
.	O
</s>
<s>
Note	O
that	O
without	O
the	O
comma	O
,	O
the	O
format	O
mirrors	O
how	O
Bencode	B-Protocol
encodes	O
strings	O
.	O
</s>
<s>
Empty	O
string	O
is	O
the	O
only	O
netstring	B-Protocol
that	O
begins	O
with	O
zero	O
.	O
</s>
<s>
There	O
is	O
exactly	O
one	O
legal	O
netstring	B-Protocol
encoding	O
for	O
any	O
byte	O
string	O
.	O
</s>
<s>
Since	O
the	O
format	O
is	O
easy	O
to	O
generate	O
and	O
to	O
parse	B-Language
,	O
it	O
is	O
easy	O
to	O
support	O
by	O
programs	O
written	O
in	O
different	O
programming	O
languages	O
.	O
</s>
<s>
In	O
practice	O
,	O
netstrings	B-Protocol
are	O
often	O
used	O
to	O
simplify	O
exchange	O
of	O
bytestrings	O
,	O
or	O
lists	O
of	O
bytestrings	O
.	O
</s>
<s>
For	O
example	O
,	O
see	O
its	O
use	O
in	O
the	O
Simple	B-Protocol
Common	I-Protocol
Gateway	I-Protocol
Interface	I-Protocol
(	O
SCGI	B-Protocol
)	O
and	O
the	O
Quick	B-Protocol
Mail	I-Protocol
Queuing	I-Protocol
Protocol	I-Protocol
(	O
QMQP	B-Protocol
)	O
.	O
</s>
<s>
Netstrings	B-Protocol
avoid	O
complications	O
that	O
arise	O
in	O
trying	O
to	O
embed	O
arbitrary	O
data	O
in	O
delimited	B-Algorithm
formats	O
.	O
</s>
<s>
For	O
example	O
,	O
XML	O
may	O
not	O
contain	O
certain	O
byte	O
values	O
and	O
requires	O
a	O
nontrivial	O
combination	O
of	O
escaping	B-Algorithm
and	O
delimiting	B-Algorithm
,	O
while	O
generating	O
multipart	O
MIME	O
messages	O
involves	O
choosing	O
a	O
delimiter	B-Algorithm
that	O
must	O
not	O
clash	O
with	O
the	O
content	O
of	O
the	O
data	O
.	O
</s>
<s>
Netstrings	B-Protocol
can	O
be	O
stored	O
recursively	O
.	O
</s>
<s>
example	O
to	O
instead	O
be	O
a	O
sequence	O
of	O
two	O
netstrings	B-Protocol
,	O
itself	O
encoded	O
as	O
a	O
single	O
netstring	B-Protocol
,	O
gives	O
the	O
following	O
:	O
</s>
<s>
Parsing	B-Language
such	O
a	O
nested	O
netstring	B-Protocol
is	O
an	O
example	O
of	O
duck	B-Application
typing	I-Application
,	O
since	O
the	O
contained	O
string	O
(	O
"	O
5:hello	O
,	O
6:world	O
!,	O
"	O
)	O
is	O
both	O
a	O
string	O
and	O
a	O
sequence	O
of	O
netstrings	B-Protocol
.	O
</s>
<s>
Its	O
effective	O
type	O
is	O
determined	O
by	O
how	O
the	O
application	O
chooses	O
to	O
interpret	O
it	O
,	O
not	O
by	O
any	O
explicit	O
type	O
declaration	O
required	O
by	O
the	O
netstring	B-Protocol
specification	O
.	O
</s>
<s>
In	O
general	O
,	O
there	O
are	O
3	O
ways	O
that	O
a	O
program	O
expecting	O
a	O
netstring	B-Protocol
may	O
choose	O
to	O
interpret	O
its	O
contents	O
:	O
</s>
<s>
As	O
encapsulated	O
metadata	O
and	O
data	O
,	O
using	O
a	O
tagged	B-Language
union	I-Language
convention	O
to	O
describe	O
the	O
types	O
of	O
nested	O
netstrings	B-Protocol
,	O
thereby	O
establishing	O
a	O
self-describing	O
hierarchical	O
data	B-Application
serialization	I-Application
format	O
.	O
</s>
<s>
Note	O
that	O
since	O
netstrings	B-Protocol
pose	O
no	O
limitations	O
on	O
the	O
contents	O
of	O
the	O
data	O
they	O
store	O
,	O
netstrings	B-Protocol
can	O
not	O
be	O
embedded	O
verbatim	O
in	O
most	O
delimited	B-Algorithm
formats	O
without	O
the	O
possibility	O
of	O
interfering	O
with	O
the	O
delimiting	B-Algorithm
of	O
the	O
containing	O
format	O
.	O
</s>
<s>
In	O
the	O
context	O
of	O
network	O
programming	O
it	O
is	O
potentially	O
useful	O
that	O
the	O
receiving	O
program	O
is	O
informed	O
of	O
the	O
size	O
of	O
the	O
data	O
that	O
follows	O
,	O
as	O
it	O
can	O
allocate	B-General_Concept
exactly	O
enough	O
memory	O
,	O
avoid	O
the	O
need	O
for	O
reallocation	O
to	O
accommodate	O
more	O
data	O
,	O
and	O
preemptively	O
reject	O
data	O
that	O
would	O
exceed	O
size	O
limits	O
.	O
</s>
