@@ -15,48 +15,77 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
15
15
document are to be interpreted as described in [ RFC
16
16
2119] ( https://tools.ietf.org/html/rfc2119 ) .
17
17
18
+ ## Modes
19
+
20
+ This specification defines the following two modes:
21
+
22
+ * ** Reliable/Ordered** : Intended for reliable and ordered transmission
23
+ of chunks. The application that is reassembling chunks into a message
24
+ MUST ensure that chunks of a message are not reordered. Furthermore,
25
+ chunks of different messages SHALL NOT be interleaved.
26
+ * ** Unreliable/Unordered** : Intended for transmission of chunks where
27
+ chunks MAY be lost or reordered. Additionally, an implementation MAY
28
+ optionally be able to handle duplicated chunks.
29
+
18
30
## Chunk Size
19
31
20
32
The term * chunk size* is referring to the resulting size from the
21
33
concatenation of * chunk header* and * chunk data* in bytes.
22
34
23
35
## Chunk Header
24
36
25
- When converting data to chunks, a 9 byte header MUST be prepended to
26
- each chunk. This allows for sending a chunk over the network in any
27
- order.
28
-
29
- ### Length
30
-
31
- The header is 9 bytes long.
37
+ When converting data to chunks, a header MUST be prepended to each
38
+ chunk of the following byte size:
32
39
33
- ### Format
40
+ * 1 byte ** short header** for reliable/ordered mode, and
41
+ * 9 byte ** long header** for unreliable/unordered mode.
34
42
35
- The header is encoded in binary using network-oriented format (most
36
- significant byte first, also known as big-endian). It is structured as
37
- follows:
43
+ Both header variants are encoded in binary using network-oriented format
44
+ (most significant byte first, also known as big-endian).
38
45
39
- |O|IIII|SSSS|
46
+ ### Short Header
40
47
41
- - O: Options bit field (1 byte)
42
- - I: Message id (4 bytes)
43
- - S: Serial number (4 bytes)
48
+ The short header contains a single byte called the * options bit field* :
44
49
45
50
** Options bit field**
46
51
47
52
The * options bit field* field is used to encode additional information
48
- about a chunk. Right now, only the least significant bit is being used.
49
- The other bits are reserved and MUST be set to ` 0 ` .
53
+ about a chunk.
50
54
51
55
MSB LSB
52
56
+---------------+
53
- |0 0 0 0 0 0 0 E|
57
+ |R R R R R M M E|
54
58
+---------------+
55
59
60
+ - R: Reserved, MUST be 0.
61
+
62
+ - M: Mode with the following values:
63
+
64
+ 11 - reliable/ordered
65
+ 10 - reserved
66
+ 01 - reserved
67
+ 00 - unreliable/unordered
68
+
56
69
- E: End-of-message, this MUST be set to 1 if this is the
57
70
last chunk of the message. Otherwise, it MUST be set
58
71
to 0.
59
72
73
+ ### Long Header
74
+
75
+ The long header contains a total of 9 bytes and is structured in the
76
+ following way:
77
+
78
+ |O|IIII|SSSS|
79
+
80
+ - O: Options bit field (1 byte)
81
+ - I: Message id (4 bytes)
82
+ - S: Serial number (4 bytes)
83
+
84
+ ** Options bit field**
85
+
86
+ Identical to the * options bit field* of the
87
+ [ Short Header] ( #short-header ) format.
88
+
60
89
** Message id**
61
90
62
91
The * message id* SHALL be any 32 bit unsigned integer. It is RECOMMENDED
@@ -73,27 +102,58 @@ with 0 and MUST be incremented by 1 for every chunk.
73
102
The chunk data MUST be appended to the chunk header. It MUST contain at
74
103
least 1 byte of data.
75
104
76
- Every chunk MUST contain up to ` chunk size - 9 ` bytes of data. Only the
77
- last chunk of a message may contain less than ` chunk size - 9 ` bytes of
78
- chunk data.
105
+ Every chunk MUST contain up to ` chunk size - header size ` bytes of
106
+ data unless it is the last chunk of a message in which case it MAY
107
+ contain less than ` chunk size - header size ` bytes of data.
79
108
80
- The chunk data MUST be chunked in a non-overlapping sequential way.
109
+ The chunk data MUST be chunked in a non-overlapping, sequential way.
81
110
82
111
## Example
83
112
84
- When chunking the byte sequence ` 12345678 ` with a chunk size of 12 and
85
- the message id 42, the data MUST be chunked into the following three
86
- chunks:
113
+ ### Reliable/Ordered Mode
114
+
115
+ When chunking the byte sequence ` 12345678 ` (where each digit is an 8
116
+ bit unsigned integer) with a chunk size of 6, the data is being chunked
117
+ into the following two chunks:
118
+
119
+ - First chunk: `0b00000110 || 0x0102030405`
120
+ - Second chunk: `0b00000111 || 0x060708`
121
+
122
+ ### Unreliable/Unordered Mode
123
+
124
+ When chunking the byte sequence ` 12345678 ` (where each digit is an 8
125
+ bit unsigned integer) with a chunk size of 12 and the message id 42,
126
+ the data is being chunked into the following three chunks:
87
127
88
128
- First chunk: `0b00000000 || 0x0000002a || 0x00000000 || 0x010203`
89
129
- Second chunk: `0b00000000 || 0x0000002a || 0x00000001 || 0x040506`
90
130
- Third chunk: `0b00000001 || 0x0000002a || 0x00000002 || 0x0708`
91
131
92
132
## Unchunking
93
133
94
- Implementations MUST support unchunking of chunks that arrive in
95
- arbitrary order. This is usually done by keeping track of messages and
96
- the corresponding chunks.
97
-
134
+ In unordered/unreliable mode, implementations MUST support unchunking of
135
+ chunks that arrive in arbitrary order. This is usually done by keeping
136
+ track of messages and the corresponding chunks.
98
137
In order to prevent memory leaks when chunks are lost in transmission,
99
138
implementations SHOULD provide a way to clean up incomplete messages.
139
+
140
+ Implementations of the * unreliable/unordered* mode MAY optionally be
141
+ able to handle duplicated chunks.
142
+
143
+ ## Changelog
144
+
145
+ ### 2019-02-06
146
+
147
+ Version 1.1
148
+
149
+ ** Important** : Backwards compatibility to 1.0 can only be ensured by
150
+ using the unreliable/unordered mode.
151
+
152
+ * Add reliable/ordered mode with 1 byte header
153
+
154
+ ### 2016-09-29
155
+
156
+ Version 1.0
157
+
158
+ * Define unreliable/unordered mode with 9 byte header
159
+
0 commit comments