DecoderFallbackBuffer 類別

定義

提供緩衝區,允許後援處理常式在無法解碼輸入位元組序列時,將替代字串傳回至解碼器。Provides a buffer that allows a fallback handler to return an alternate string to a decoder when it cannot decode an input byte sequence.

public ref class DecoderFallbackBuffer abstract
public abstract class DecoderFallbackBuffer
type DecoderFallbackBuffer = class
Public MustInherit Class DecoderFallbackBuffer
繼承
DecoderFallbackBuffer
衍生

備註

編碼定義 Unicode 字元與編碼的位元組序列之間的對應。An encoding defines a mapping between a Unicode character and an encoded sequence of bytes. 如果未針對特定位元組序列定義對應,則會將輸入位元組序列轉換為輸出字元的解碼作業失敗。A decoding operation, which converts an input byte sequence to an output character, fails if no mapping is defined for a particular byte sequence.

如果無法執行轉換,.NET Framework 會提供失敗處理機制(稱為 fallback)。The .NET Framework provides a failure handling mechanism, called a fallback, if a conversion cannot be performed. 所有的解碼器回溯處理常式都必須執行下列動作:All decoder fallback handlers must implement the following:

  • 以衍生自類別的類別表示的解碼器回溯 DecoderFallbackA decoder fallback, which is represented by a class derived from the DecoderFallback class.

  • 以衍生自類別的型別表示的解碼器回溯緩衝區, DecoderFallbackBuffer 可將字串傳回轉換作業。A decoder fallback buffer, which is represented by a type derived from the DecoderFallbackBuffer class that can return a string to the conversion operation.

回退可以使用三個策略來處理轉換失敗:Fallbacks can use three strategies to handle conversion failures:

執行中的緩衝區 DecoderFallbackBuffer 代表要傳回給解碼器的整個字串,以回應解碼器回復。The buffer in a DecoderFallbackBuffer implementation represents the entire string to be returned to the decoder in response to a decoder fallback. 一般情況下,實值也包含狀態資訊,例如要傳回給解碼器的下一個字元的索引,以及要傳回的剩餘字元數。Generally, implementations also include state information, such as the index of the next character to return to the decoder and the number of remaining characters to be returned. 由於 DecoderFallbackBuffer 是抽象類別,因此它需要衍生類別至少執行下列成員:Because DecoderFallbackBuffer is an abstract class, it requires derived classes to implement the following members at a minimum:

  • Fallback方法,當它無法將位元組序列解碼時,它會呼叫此方法。The Fallback method, which is called by the decoder when it cannot decode a byte sequence. 此解碼器會將兩項資訊傳遞給回溯緩衝區執行:一個陣列,其中包含無法解碼的位元組,以及輸入位元組陣列中第一個位元組的索引。The decoder passes two pieces of information to the fallback buffer implementation: an array containing the bytes that could not be decoded and the index of the first byte in the input byte array. 在「解碼」回例外狀況處理常式中,會在此方法中擲回例外狀況。In a decoder fallback exception handler, the exception is thrown in this method. 否則,如果方法提供回復,則會傳回 true ,否則 false 會傳回。Otherwise, the method returns true if it provides a fallback, or false if it does not.

  • GetNextChar如果方法傳回,則為由解碼器重複呼叫的方法 Fallback trueThe GetNextChar method, which is called repeatedly by the decoder if the Fallback method returns true. 在後續呼叫中,處理常式應該會傳回其緩衝區中的每個字元。In successive calls, the handler should return each character in its buffer. 當它傳回所有字元時,它應該會傳回 U + 0000。When it has returned all characters, it should return U+0000. 例外狀況回溯處理常式一律會傳回 U + 0000。An exception fallback handler always returns U+0000.

  • MovePrevious方法,這個方法會嘗試將指標移至緩衝區中的上一個位置,並指出移動是否成功。The MovePrevious method, which tries to move the pointer to the previous position in the buffer and indicates whether the move was successful. 例外狀況處理常式一律會傳回 falseAn exception handler always returns false.

  • Remaining屬性,指出要傳回給解碼器的剩餘字元數。The Remaining property, which indicates the number of remaining characters to be returned to the decoder. 例外狀況回退處理常式一律會傳回零。An exception fallback handler always returns zero.

建構函式

DecoderFallbackBuffer()

初始化 DecoderFallbackBuffer 類別的新執行個體。Initializes a new instance of the DecoderFallbackBuffer class.

屬性

Remaining

在衍生類別中覆寫時,於目前的 DecoderFallbackBuffer 物件中取得仍要處理的字元數。When overridden in a derived class, gets the number of characters in the current DecoderFallbackBuffer object that remain to be processed.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Fallback(Byte[], Int32)

在衍生類別中覆寫時,預備後援緩衝區來處理指定的輸入位元組序列。When overridden in a derived class, prepares the fallback buffer to handle the specified input byte sequence.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetNextChar()

在衍生類別中覆寫時,擷取後援緩衝區中的下一個字元。When overridden in a derived class, retrieves the next character in the fallback buffer.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MovePrevious()

在衍生類別中覆寫時,會使 GetNextChar() 方法的下一個呼叫存取在目前字元位置之前的資料緩衝區字元位置。When overridden in a derived class, causes the next call to the GetNextChar() method to access the data buffer character position that is prior to the current character position.

Reset()

初始化與後援緩衝區有關的所有資料和狀態資訊。Initializes all data and state information pertaining to this fallback buffer.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱