第四十一回スパルタンプログラミング
6/22週は残業時間の調整で早めに仕事を終わらし帰り、恩師すすめの「播磨灘物語」読み始める。
右肩は意図的にストレッチしてることもあり、大分ほぐれてきて可動範囲が骨折前に近くなってきた。
中に支えが入ってる分の違和感と突っ張った感じはとれない。
今までなかった物が入ってるんだから、そりゃそうか。
6/27の晩飯は太平楽の五目ラーメン。麻婆麺のがうまいが、いつも同じじゃつまらん。
6/28はサイクルショップ光にホイール購入の相談に行くつもりだったけど、内灘サイクルロードレースで休みだった。
やりたいこと
- HPACK 5.2の形に実装を整理したい。
- エンコード部分へまいる!
やったこと
- HPACK5.2の形にした。これによりデコード部分の一通りは終わり。
HPACKのエンコード部分の勉強
nghttp2に学ぼう!deflate.cから追いかけると、
- main()でnvaにエンコード前のヘッダリストを用意。
- deflate()のbuflen = nghttp2_hd_deflate_bound(deflater, nva, nvlen)で圧縮対象のためのbufのupper boundを計算して、malloc。nvlenはヘッダリストの長さ。
- nghttp2_hd_deflate_hd(deflater, buf, buflen, nva, nvlen)で圧縮。
2.は下記がソースだけど、
size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater _U_, const nghttp2_nv *nva, size_t nvlen) { size_t n = 0; size_t i; /* Possible Maximum Header Table Size Change. Encoding (1u << 31) - 1 using 4 bit prefix requires 6 bytes. We may emit this at most twice. */ n += 12; /* Use Literal Header Field without indexing - New Name, since it is most space consuming format. Also we choose the less one between non-huffman and huffman, so using literal byte count is sufficient for upper bound. Encoding (1u << 31) - 1 using 7 bit prefix requires 6 bytes. We need 2 of this for |nvlen| header fields. */ n += 6 * 2 * nvlen; for (i = 0; i < nvlen; ++i) { n += nva[i].namelen + nva[i].valuelen; } return n; }
Use Literal Header Field without indexingはたぶん以下。
- 整数表現がEncode(INT32_MAX, 7 bit prefix)が6byte、
- それがnameとvalueの2つ、
- でnvlenをかける。
- それとforループでliteral表現の長さを足す。
Possible Maximum Header Table Size Changeは?。
- これがUse Literal Header Field without indexingのインデックス部なら、
- 整数表現がEncode(INT32_MAX, 4 bit prefix)が6byteで理解できるかなと思った。
- がWe may emit this at most twiceが?になってしまう。そもそも、Possible Maximum Header Table Size Changeって書いてあるし。
nghttp2で他に気づいたこと
- testにCUnitを使うようになってた。
- static tableのindex検索にhash値を使わなくなってた。
エンコード関数を書き始めるのにとっかかりが必要
- 送りたいheaderlistが決まる。
- indexになるか、staticとdynamicを検索
- あれば、indexに置き換えて、つめる。
- なければ、huffman符号化してつめる。
- 次へ
- indexになるか、staticとdynamicを検索
と方針を決めるとする。とやるべき課題は2つ
- static, dynamic tableの高速な検索関数の作成
- huffman符号化の高速な関数の作成