デコーダー【decoder】
デコーダー Decoder
デコーダ
デコーダとは、データの圧縮や暗号化など、符号化されたデータを復号化する(元に戻す)機能を持つもののことである。
デコーダはデコードするもの全般を指すので、圧縮ファイルの解凍、暗号化された情報の復号、MP3などの音声圧縮ファイルの再生、などはデコーダによって行われるといえる。デコーダはソフトウェアとして実現されているものもあれば、チップに実装されてハードウェア的に実現されているものもある。
デコーダの対義語はエンコーダで、データをある規則で圧縮したり暗号化したりする符号化のためのソフトウェアのことを指す。デコーダが対応していないエンコーダで処理されたデータは、複合化できない。
デコーダはバーコードリーダのような機器でも利用されている。バーコードリーダでは、検出された波形をデータとして取り込み、データのロジック値を正確に解析し、一度のスキャニングでデータを認識している。
Decoder クラス
アセンブリ: mscorlib (mscorlib.dll 内)


エンコーディングは、文字のセットをバイト シーケンスに変換するプロセスです。デコードはその逆になります。エンコードされたバイト シーケンスを文字のセットに変換するプロセスです。
Decoder では、複数のブロックにまたがるバイト シーケンスを正確にデコードできるように、GetChars への連続する呼び出し間でステータス情報を維持します。また、Decoder は、データ ブロックの末尾で後続バイトを保持し、その後続バイトを次のデコード操作に使用します。したがって、GetDecoder と GetEncoder は、ネットワーク伝送やファイル操作に役立ちます。これは、ネットワーク伝送やファイル操作では、完全なデータ ストリームではなくデータのブロックを処理することが多いためです。
GetCharCount メソッドは、バイト シーケンスをデコードした結果生成される文字数を判断し、GetChars メソッドは、実際にデコードを実行します。
このクラスの実装のインスタンスを取得するには、Encoding 実装の GetDecoder メソッドを使用します。
バージョンの考慮事項Decoder オブジェクトまたは Encoder オブジェクトは、変換演算の実行時にシリアル化できます。オブジェクトが .NET Framework の同じバージョンで逆シリアル化された場合、オブジェクトの状態は保持されますが、別のバージョンで逆シリアル化された場合には、オブジェクトの状態は失われます。

Decoder を使用して、2 つの異なるバイト配列を 1 つの文字配列に変換するコード例を次に示します。文字のバイトのいずれかが配列にまたがっています。これは、ストリームを読み取るときの System.IO.StreamReader の内部処理と似ています。
Imports System Imports System.Text Public Class dec Public Shared Sub Main() ' These bytes in UTF-8 correspond to 3 different Unicode ' characters: space (U+0020), # (U+0023), and the biohazard ' symbol (U+2623). Note the biohazard symbol requires 3 bytes ' in UTF-8 (hexadecimal e2, 98, a3). Decoders store state across ' multiple calls to GetChars, handling the case when one char ' is in multiple byte arrays. Dim bytes1 As Byte() = {&H20, &H23, &HE2} Dim bytes2 As Byte() = {&H98, &HA3} Dim chars(3) As Char Dim d As Decoder = Encoding.UTF8.GetDecoder() Dim charLen As Integer = d.GetChars(bytes1, 0, bytes1.Length, chars, 0) ' The value of charLen should be 2 now. charLen += d.GetChars(bytes2, 0, bytes2.Length, chars, charLen) Dim c As Char For Each c In chars Console.Write("U+{0:X4} ", Convert.ToUInt16(c) ) Next c End Sub End Class
using System; using System.Text; public class dec { public static void Main() { // These bytes in UTF-8 correspond to 3 different Unicode // characters: space (U+0020), # (U+0023), and the biohazard // symbol (U+2623). Note the biohazard symbol requires 3 bytes // in UTF-8 (hexadecimal e2, 98, a3). Decoders store state across // multiple calls to GetChars, handling the case when one char // is in multiple byte arrays. byte[] bytes1 = { 0x20, 0x23, 0xe2 }; byte[] bytes2 = { 0x98, 0xa3 }; char[] chars = new char[3]; Decoder d = Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(bytes1, 0, bytes1.Length, chars, 0); // The value of charLen should be 2 now. charLen += d.GetChars(bytes2, 0, bytes2.Length, chars, charLen); foreach(char c in chars) Console.Write("U+{0:X4} ", (ushort)c); } }
using namespace System; using namespace System::Text; int main() { // These bytes in UTF-8 correspond to 3 different Unicode // characters: space (U+0020), # (U+0023), and the biohazard // symbol (U+2623). Note the biohazard symbol requires 3 bytes // in UTF-8 (hexadecimal e2, 98, a3). Decoders store state across // multiple calls to GetChars, handling the case when one char // is in multiple byte arrays. array<Byte>^bytes1 = {0x20,0x23,0xe2}; array<Byte>^bytes2 = {0x98,0xa3}; array<Char>^chars = gcnew array<Char>(3); Decoder^ d = Encoding::UTF8->GetDecoder(); int charLen = d->GetChars( bytes1, 0, bytes1->Length, chars, 0 ); // The value of charLen should be 2 now. charLen += d->GetChars( bytes2, 0, bytes2->Length, chars, charLen ); for ( UInt16 index(0); index < chars->Length; ++index ) { Console::Write( "U+{0:X4} ", static_cast<UInt16>(chars[ index ]) ); } }
import System.*; import System.Text.*; public class Dec { public static void main(String[] args) { // These bytes in UTF-8 correspond to 3 different Unicode // characters: space (U+0020), # (U+0023), and the biohazard // symbol (U+2623). Note the biohazard symbol requires 3 bytes // in UTF-8 (hexadecimal e2, 98, a3). Decoders store state across // multiple calls to GetChars, handling the case when one char // is in multiple byte arrays. ubyte bytes1[] = { 0x20, 0x23, 0xE2 }; ubyte bytes2[] = { 0x98, 0xA3 }; char chars[] = new char[3]; Decoder d = Encoding.get_UTF8().GetDecoder(); int charLen = d.GetChars(bytes1, 0, bytes1.length, chars, 0); // The value of charLen should be 2 now. charLen += d.GetChars(bytes2, 0, bytes2.length, chars, charLen); for (int iCtr = 0; iCtr < chars.length; iCtr++) { char c = chars[iCtr]; Console.Write("U+{0} ",((Int16)c).ToString("X4")); } } //main } //Dec

System.Text.Decoder


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Decoder コンストラクタ
アセンブリ: mscorlib (mscorlib.dll 内)



次のコード例は、新しい Decoder インスタンスを初期化する 2 つの方法を示しています。
Imports System Imports System.Text Class EncoderExample Public Shared Sub Main() ' A Decoder is obtained from an Encoding. Dim uni As New UnicodeEncoding() Dim dec1 As Decoder = uni.GetDecoder() ' A more direct technique. Dim dec2 As Decoder = Encoding.Unicode.GetDecoder() ' dec1 and dec2 seem to be the same. Console.WriteLine(dec1.ToString()) Console.WriteLine(dec2.ToString()) ' Note that their hash codes differ. Console.WriteLine(dec1.GetHashCode()) Console.WriteLine(dec2.GetHashCode()) End Sub End Class
using System; using System.Text; class EncoderExample { public static void Main() { // A Decoder is obtained from an Encoding. UnicodeEncoding uni = new UnicodeEncoding(); Decoder dec1 = uni.GetDecoder(); // A more direct technique. Decoder dec2 = Encoding.Unicode.GetDecoder(); // dec1 and dec2 seem to be the same. Console.WriteLine(dec1.ToString()); Console.WriteLine(dec2.ToString()); // Note that their hash codes differ. Console.WriteLine(dec1.GetHashCode()); Console.WriteLine(dec2.GetHashCode()); } }
using namespace System; using namespace System::Text; int main() { // A Decoder is obtained from an Encoding. UnicodeEncoding^ uni = gcnew UnicodeEncoding; Decoder^ dec1 = uni->GetDecoder(); // A more direct technique. Decoder^ dec2 = Encoding::Unicode->GetDecoder(); // dec1 and dec2 seem to be the same. Console::WriteLine( dec1 ); Console::WriteLine( dec2 ); // Note that their hash codes differ. Console::WriteLine( dec1->GetHashCode() ); Console::WriteLine( dec2->GetHashCode() ); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Decoder プロパティ

名前 | 説明 | |
---|---|---|
![]() | Fallback | 現在の Decoder オブジェクトの DecoderFallback オブジェクトを取得または設定します。 |
![]() | FallbackBuffer | 現在の Decoder オブジェクトに関連付けられている DecoderFallbackBuffer オブジェクトを取得します。 |

Decoder メソッド

名前 | 説明 | |
---|---|---|
![]() | Convert | オーバーロードされます。 エンコード済みバイト シーケンスを文字列または文字配列に変換します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetCharCount | オーバーロードされます。 派生クラスでオーバーライドされた場合、バイト シーケンスをデコードすることによって生成される文字数を計算します。 |
![]() | GetChars | オーバーロードされます。 派生クラスでオーバーライドされた場合、バイト シーケンスを文字のセットにデコードします。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Reset | 派生クラスでオーバーライドされた場合、デコーダを初期状態に戻します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

Decoder メンバ
エンコード済みバイト シーケンスを文字のセットに変換します。
Decoder データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Fallback | 現在の Decoder オブジェクトの DecoderFallback オブジェクトを取得または設定します。 |
![]() | FallbackBuffer | 現在の Decoder オブジェクトに関連付けられている DecoderFallbackBuffer オブジェクトを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Convert | オーバーロードされます。 エンコード済みバイト シーケンスを文字列または文字配列に変換します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetCharCount | オーバーロードされます。 派生クラスでオーバーライドされた場合、バイト シーケンスをデコードすることによって生成される文字数を計算します。 |
![]() | GetChars | オーバーロードされます。 派生クラスでオーバーライドされた場合、バイト シーケンスを文字のセットにデコードします。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Reset | 派生クラスでオーバーライドされた場合、デコーダを初期状態に戻します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- Decoderのページへのリンク