Netstrings

Netstrings

In computer programming, a netstring refers to a self-delimited way of encoding a (byte)string, defined in a document by D. J. Bernstein.

Netstrings store the byte length data that follows, making it easier to unambiguously pass text and byte data between programs that could be sensitive to values that could be interpreted as delimiters or terminators (such as a null character).

The format consists of the string's length written using ASCII digits, followed by a colon, the data, and a comma. For example, "hello world!" encodes as: 12:hello world!,And an empty string as: 0:,The comma makes it slightly simpler for humans to read netstrings that are used as adjacent records, and provides weak verification of correct parsing. Note that without the comma, the format mirrors how Bencode encodes strings.

Since the format is easy to generate and to parse, it is easy to support by programs written in different programming languages. In practice, netstrings are often used to simplify exchange of bytestrings, or lists of bytestrings. For example, see its use in the Simple Common Gateway Interface (SCGI) and the Quick Mail Queuing Protocol (QMQP) .

Netstrings avoid complications that arise in trying to embed arbitrary data in delimited formats. For example, XML may not contain certain byte values and requires a nontrivial combination of escaping and delimiting, while generating multipart MIME messages involves choosing a delimiter that must not clash with the content of the data.

Note that since netstrings pose no limitations on the contents of the data they store, netstrings can not be embedded verbatim in most delimited formats without the possibility of them interfering with the delimiting of the containing format.

In the context of network programming it is potentially useful that the receiving program is informed of the size of the data that follows, as it can allocate exactly enough memory and so avoid the need for reallocation to accommodate more data.

External links

* http://cr.yp.to/proto/netstrings.txt
* http://wiki.tcl.tk/15074


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Netstring — In computer programming, a netstring is a formatting method for byte strings that uses a declarative notation to indicate the size of the string. [1][2] Netstrings store the byte length of the data that follows, making it easier to unambiguously… …   Wikipedia

  • Comparison of data serialization formats — This is a comparison of data serialization formats, different ways to convert complex objects to sequences of bits. It does not include markup languages used exclusively as document file formats. Contents 1 Overview 2 Syntax comparison of human… …   Wikipedia

  • SCGI — Das Simple Common Gateway Interface (SCGI) ist ein Standard für den Datenaustausch zwischen einem Webserver und dritter Software, die Anfragen bearbeitet. Es ist eine Alternative zu klassischem CGI und ähnelt dem FastCGI Protokoll. Die… …   Deutsch Wikipedia

  • Simple Common Gateway Interface — The Simple Common Gateway Interface (SCGI) is a protocol for applications to interface with HTTP servers, an alternative to the CGI protocol. It is similar to FastCGI but is designed to be easier to implement.The specification document was placed …   Wikipedia

  • Simple Common Gateway Interface — Das Simple Common Gateway Interface (SCGI) ist ein Standard für den Datenaustausch zwischen einem Webserver und dritter Software, die Anfragen bearbeitet. Es ist eine Alternative zu klassischem CGI und ähnelt dem FastCGI Protokoll. Die… …   Deutsch Wikipedia

  • SCGI — Simple Common Gateway Interface (SCGI) протокол по взаимодействию приложений с веб (http) серверами, разработанный как альтернатива Common Gateway Interface. Он похож на FastCGI, но проще в реализации. Спецификация была опубликована Neil… …   Википедия

  • Bencode — (pronounced Bee Encode ) is the encoding used by the peer to peer file sharing system BitTorrent for storing and transmitting loosely structured data.It supports four different types of values: * byte strings, * integers, * lists, and *… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”