You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-31Lines changed: 33 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
-
Netstring parsing
2
-
=================
1
+
Netstring for C
2
+
===============
3
3
4
4
A [netstring](http://en.wikipedia.org/wiki/Netstring) is a way of encoding a sequence of bytes for transmission over a network, or for serialization. They're very easy to work with. They encode the data's length, and can be concatenated trivially. The format was [defined by D. J. Bernstein](http://cr.yp.to/proto/netstrings.txt) and is used in various software. Examples of netstrings:
5
5
@@ -18,7 +18,37 @@ Basic API
18
18
19
19
All the code is in `netstring.c` and `netstring.h`, and these have no external dependencies. To use them, just include them in your application. Include `netstring.h` and link with the C code.
20
20
21
-
### Parsing netstrings
21
+
Creating netstrings
22
+
-------------------
23
+
24
+
You can create your netstrings manually like in this example:
25
+
26
+
sprintf(buf, "%lu:%s,", strlen(str), str);
27
+
28
+
This code provides a convenience function for creating netstrings:
This allocates and creates a netstring containing the first `len` bytes of `data`. If `len` is 0 then no data will be read from `data`, and it may be null.
49
+
50
+
Parsing netstrings
51
+
------------------
22
52
23
53
To parse a netstring, use `netstring_read()`.
24
54
@@ -62,34 +92,6 @@ netstring. This restriction is in place partially to protect from
62
92
malicious or erroneous input, and partly to be compatible with
63
93
D. J. Bernstein's reference implementation.
64
94
65
-
### Creating netstrings
66
-
67
-
You can create your netstrings manually like in this example:
68
-
69
-
sprintf(buf, "%lu:%s,", strlen(str), str);
70
-
71
-
This code provides a convenience function for creating netstrings:
This allocates and creates a netstring containing the first `len` bytes of `data`. If `len` is 0 then no data will be read from `data`, and it may be null.
92
-
93
95
Message Framing on stream-based connections (sockets, pipes...)
0 commit comments