2.2.2 Record Size Encoding
For the variable-sized records that are used by this protocol, the record needs to contain the size, in octets, of the content. An implementation SHOULD support record sizes as large as 0xffffffff octets (encoded size requires five octets).<2>
As represented in the following figure, the encoding algorithm takes the size of the record payload as input in little-endian format and generates a stream of octets. The octets MUST be sent in the order in which they are generated.
Figure 2: The encoding algorithm
The following table lists the encoded sizes for the range of values of Size, which is computed as previously explained. The network ordering of octets is top-down. For example, if the size is in the range 0x80-0x3FFF, the network ordering of encoded size octets is (Size & 0x7F) | 0x80 followed by Size >> 0x07.
Integer value (size) |
Encoding |
---|---|
0x00-0x7F |
Size |
0x80-0x3FFF |
(Size & 0x7F)| 0x80 Size >> 0x07 |
0x4000-0x1FFFFF |
(Size & 0x7F)| 0x80 ((Size >> 0x07) & 0x7F)| 0x80 Size >> 0x0E |
0x200000-0x0FFFFFFF |
(Size & 0x7F)| 0x80 ((Size >> 0x07) & 0x7F)| 0x80 ((Size >> 0x0E) & 0x7F)| 0x80 Size >> 0x15 |
0x10000000-0x0FFFFFFFF |
(Size & 0x7F)| 0x80 ((Size >> 0x07) & 0x7F)| 0x80 ((Size >> 0x0E) & 0x7F)| 0x80 ((Size >> 0x15) & 0x7F)| 0x80 Size >> 0x1C |
In the preceding table, "&" refers to a bitwise "and" operation, "|" refers to a bitwise "or" operation, and ">>" refers to a right-shift operation.