为什么 HTTP/2 中的流标识符是 31 位,为什么它前面有一个保留位?

Why is the stream identifier 31 bit in HTTP/2 and why is it preceded with a reserved bit?

HTTP/2 中的帧格式如下所示(来源:HTTP/2: Frame Format):

+-----------------------------------------------+
|                 Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|                 Stream Identifier (31)                      |
+=+=============================================================+
|                   Frame Payload (0...)                      ...
+---------------------------------------------------------------+

R: A reserved 1-bit field. The semantics of this bit are undefined, and the bit MUST remain unset (0x0) when sending and MUST be ignored when receiving.

Stream Indentifier: A stream identifier (see Section 5.1.1) expressed as an unsigned 31-bit integer. The value 0x0 is reserved for frames that are associated with the connection as a whole as opposed to an individual stream.

他们没有使用 32 位无符号整数是有原因的吗?为什么指定保留位必须设置为 0 并且必须被接收方忽略?

这只是对像 Java 这样没有 32 位无符号整数的语言的让步吗?

此处讨论:https://github.com/http2/http2-spec/issues/67

Purpose is for experimentation with stream reprioritization.

http://lists.w3.org/Archives/Public/ietf-http-wg/2013AprJun/0135.html

Also there to protect against some implementations having problems with signed vs. unsigned

Discussed in Hamburg; are a variety of use cases, no need to remove (now).