Skip to main content

Appendix B. Encoding and Decoding Examples (编码解码示例)

以下示例代表了编码器和解码器之间的一系列交换. 这些交换旨在演练大多数 QPACK 指令并突出可能常见的模式及其对动态表状态的影响. 编码器发送三个已编码的字段区段, 每个包含一个字段行, 以及两个未被引用的推测性插入 (Speculative Inserts).

显示了编码器动态表的状态及其当前大小. 每个条目显示条目的绝对索引 (Abs), 当前具有对该条目引用的未完成已编码字段区段的数量 (Ref), 以及名称和值. 'acknowledged' 行上方的条目已被解码器确认.

B.1 Literal Field Line with Name Reference (带名称引用的字面字段行)

编码器发送一个已编码的字段区段, 包含带有静态名称引用的字段的字面表示.

DataInterpretation
Stream: 0
0000Required Insert Count = 0, Base = 0
510b 2f69 6e64 6578 2e68 746d 6cLiteral Field Line with Name Reference
Static Table, Index=1
(:path=/index)

编码器的动态表:

Abs Ref Name        Value
^-- acknowledged --^
Size=0

B.2 Dynamic Table (动态表)

编码器设置动态表容量, 插入一个带有动态名称引用的头部, 然后发送一个引用此新条目的可能阻塞的已编码字段区段. 解码器确认处理已编码字段区段, 这隐式确认了所有动态表插入直到必需插入计数.

DataInterpretation
Stream: Encoder
3fbd01Set Dynamic Table Capacity=220
c00f 7777 772e 6578 616d 706c 652e 636f 6dInsert With Name Reference
Static Table, Index=0
(:authority=www.example.com)
c10c 2f73 616d 706c 652f 7061 7468Insert With Name Reference
Static Table, Index=1
(:path=/sample/path)

编码器的动态表:

Abs Ref Name        Value
^-- acknowledged --^
0 0 :authority www.example.com
1 0 :path /sample/path
Size=106
DataInterpretation
Stream: 4
0381Required Insert Count = 2, Base = 0
10Indexed Field Line With Post-Base Index
Absolute Index = Base(0) + Index(0) = 0
(:authority=www.example.com)
11Indexed Field Line With Post-Base Index
Absolute Index = Base(0) + Index(1) = 1
(:path=/sample/path)

编码器的动态表:

Abs Ref Name        Value
^-- acknowledged --^
0 1 :authority www.example.com
1 1 :path /sample/path
Size=106
DataInterpretation
Stream: Decoder
84Section Acknowledgment (stream=4)

编码器的动态表:

Abs Ref Name        Value
0 0 :authority www.example.com
1 0 :path /sample/path
^-- acknowledged --^
Size=106

B.3 Speculative Insert (推测性插入)

编码器使用字面名称向动态表中插入一个头部. 解码器确认接收到条目. 编码器不发送任何已编码字段区段.

DataInterpretation
Stream: Encoder
4a63 7573 746f 6d2d 6b65 790c 6375 7374 6f6d 2d76 616c 7565Insert With Literal Name
(custom-key=custom-value)

编码器的动态表:

Abs Ref Name        Value
0 0 :authority www.example.com
1 0 :path /sample/path
^-- acknowledged --^
2 0 custom-key custom-value
Size=160
DataInterpretation
Stream: Decoder
01Insert Count Increment (1)

编码器的动态表:

Abs Ref Name        Value
0 0 :authority www.example.com
1 0 :path /sample/path
2 0 custom-key custom-value
^-- acknowledged --^
Size=160

B.4 Duplicate Instruction, Stream Cancellation (复制指令, 流取消)

编码器复制动态表中的现有条目, 然后发送一个引用动态表条目(包括复制的条目)的已编码字段区段. 包含编码器流数据的数据包被延迟. 在数据包到达之前, 解码器取消流并通知编码器已编码字段区段未被处理.

DataInterpretation
Stream: Encoder
02Duplicate (Relative Index = 2)
Absolute Index = Insert Count(3) - Index(2) - 1 = 0

编码器的动态表:

Abs Ref Name        Value
0 0 :authority www.example.com
1 0 :path /sample/path
2 0 custom-key custom-value
^-- acknowledged --^
3 0 :authority www.example.com
Size=217
DataInterpretation
Stream: 8
0500Required Insert Count = 4, Base = 4
80Indexed Field Line, Dynamic Table
Absolute Index = Base(4) - Index(0) - 1 = 3
(:authority=www.example.com)
c1Indexed Field Line, Static Table Index = 1
(:path=/)
81Indexed Field Line, Dynamic Table
Absolute Index = Base(4) - Index(1) - 1 = 2
(custom-key=custom-value)

编码器的动态表:

Abs Ref Name        Value
0 0 :authority www.example.com
1 0 :path /sample/path
2 1 custom-key custom-value
^-- acknowledged --^
3 1 :authority www.example.com
Size=217
DataInterpretation
Stream: Decoder
48Stream Cancellation (Stream=8)

编码器的动态表:

Abs Ref Name        Value
0 0 :authority www.example.com
1 0 :path /sample/path
2 0 custom-key custom-value
^-- acknowledged --^
3 0 :authority www.example.com
Size=217

B.5 Dynamic Table Insert, Eviction (动态表插入, 驱逐)

编码器向动态表中插入另一个头部, 这会驱逐最旧的条目. 编码器不发送任何已编码字段区段.

DataInterpretation
Stream: Encoder
810d 6375 7374 6f6d 2d76 616c 7565 32Insert With Name Reference
Dynamic Table, Relative Index = 1
Absolute Index = Insert Count(4) - Index(1) - 1 = 2
(custom-key=custom-value2)

编码器的动态表:

Abs Ref Name        Value
1 0 :path /sample/path
2 0 custom-key custom-value
^-- acknowledged --^
3 0 :authority www.example.com
4 0 custom-key custom-value2
Size=215