同型復号

同型符号化

[38] 同型符号化同型復号は、 文字列バイト列との形式的な変換操作です。

[39] インターネットで使われるプロトコルの多くは、 伝統的にプロトコル要素の色々な部分で ASCII を使っています。 しかしネットワークに直接転送されるのはバイト列であって、 文字列とは異なっています。 これを変換するのが同型符号化同型復号の操作です。

[40] 実装上これがどう扱われるかは時と場合によります。

[41] 例えば HTTPContent-Type ヘッダーを設定する、 という操作の場合、 バイト列データ型のあるプログラミング言語では、 Content-Type というバイト列を直接リテラルとして記述すれば、 変換操作は不要です。

[42] 指定された値をパーセント符号化してからバイト列として送出する、 という操作の場合、 パーセント符号化の結果は文字列 (ASCII文字列) なので、 ASCII文字列データ型のあるプログラミング言語ならバイト列型キャストすれば使えるかもしれませんし、 Unicode文字列データ型しかないプログラミング言語なら UTF-8符号化する必要があるかもしれません。

仕様書

演算

[3] 文字列データ同型符号化 (isomorphic encode) は、 次のようにします >>2

  1. [4] 出力を、新しい空バイト列に設定します。
  2. [5] データの各符号位置符号位置について、順に、
    1. [6] 出力の末尾に、値が符号位置バイトを追加します。
  3. [7] 出力を返します。
[8] この演算は、データU+0100 以上符号位置を含まないときにしか使えません。

[28] ASCII符号化 (ASCII encode) は、 ASCII文字列に対する同型符号化です >>2

[29] この演算は、データU+0080 以上符号位置を含まないときにしか使えません。

[11] バイト列データ同型復号 (isomorphic decode) は、 次のようにします >>10

  1. [12] 出力を、新しい空文字列に設定します。
  2. [13] データの各バイトバイトについて、順に、
    1. [14] 出力の末尾に、値がバイト符号位置を追加します。
  3. [15] 出力を返します。

[30] ASCII復号 (ASCII decode) は、 ASCIIバイトに対する同型復号です >>10

[31] この演算は、データ0x80 以上バイトを含まないときにしか使えません。

文脈

[18] 同型符号化は、次の場面で使われています。

[19] 同型符号化応用

[20] この他に、仕様書ではUTF-8符号化UTF-8復号となっていても、 実質的に同型符号化同型復号を表していることがあります。

[22] 同型復号の用法は、復号も参照。

[44] TypedArray の歴史の項も参照。

関連

[9] Perlバイト列文字列として扱うことができます。これは同型復号に相当する暗黙の型変換を伴っています。 utf8::upgrade

[43] Unicode制御文字を使う方法は同形復号的に定義されています。 制御文字

歴史

[1] Define isomorphic encode and decode (annevk著, ) https://github.com/whatwg/infra/commit/8d7447e5462f2cd104b7bbe7a719227be80921cf

[16] byte sequence <> string by annevk · Pull Request #146 · whatwg/infra () https://github.com/whatwg/infra/pull/146

[17] 実装によっては ISO 8859-1Latin1 という名称の文字コードとしてこの符号化復号が実装されていることがありますが、 その意味には混乱があるため (例えば Web では Windows-1252 の意)、 演算名に使うことは避けられているようです。

[21] Define the HTTP Refresh header (annevk著, ) https://github.com/whatwg/html/commit/7e9f6b6ffe2119f43f909f71773a25a7e8a61ca7

[23] 28339 – <meta refresh> Specify Refresh HTTP header () https://www.w3.org/Bugs/Public/show_bug.cgi?id=28339

[24] Allow Range header to be set by APIs (jakearchibald著, ) https://github.com/whatwg/fetch/commit/819d8c9d6617986a831ecd9cf21c34ba9589a890

[25] Editorial: replace UTF-8 encode with isomorphic encode (annevk著, ) https://github.com/whatwg/fetch/commit/ffbaefb5c4f68b9d619e9db6491fd665a30a2ffb

[26] Editorial: replace UTF-8 encode with isomorphic encode by annevk · Pull Request #742 · whatwg/fetch () https://github.com/whatwg/fetch/pull/742

[27] Add ASCII encode and decode algorithms (jyasskin著, ) https://github.com/whatwg/infra/commit/1d200b6e6f1d34114f18a4faaedd189291cf621f

[32] Add ASCII encode and decode algorithms. by jyasskin · Pull Request #209 · whatwg/infra () https://github.com/whatwg/infra/pull/209

[33] Add ASCII encode and decode algorithms. by jyasskin · Pull Request #209 · whatwg/infra () https://github.com/whatwg/infra/pull/209

[34] Editorial: use "isomorphic decode" for Refresh header steps (irrationalRock著, ) https://github.com/whatwg/html/commit/bef6f783084cdb6e591f2a9d8c731180413e8ef2

[35] Use "isomorphic decode" explicitly for Refresh headers · Issue #3924 · whatwg/html () https://github.com/whatwg/html/issues/3924

[36] Changed Comment to Mention "isomorphic decode" by irrationalRock · Pull Request #3941 · whatwg/html () https://github.com/whatwg/html/pull/3941

[37] Change query state slightly to better deal with non-UTF-8 encodings (annevk著, ) https://github.com/whatwg/url/commit/f0e4390bf882446445e944215524ff3877aac95a