private void InitBinHexDecoder() { if (_binHexDecoder == null) { _binHexDecoder = new BinHexDecoder(); } else { _binHexDecoder.Reset(); } _decoder = _binHexDecoder; }
public override async Task <int> ReadContentAsBinHexAsync(byte[] buffer, int index, int count) { switch (_state) { case State.Initial: case State.EndOfFile: case State.Closed: case State.Error: return(0); case State.ClearNsAttributes: case State.PopNamespaceScope: switch (NodeType) { case XmlNodeType.Element: throw CreateReadContentAsException("ReadContentAsBinHex"); case XmlNodeType.EndElement: return(0); case XmlNodeType.Attribute: if (_curNsAttr != -1 && reader.CanReadBinaryContent) { CheckBuffer(buffer, index, count); if (count == 0) { return(0); } if (_nsIncReadOffset == 0) { // called first time on this ns attribute if (_binDecoder != null && _binDecoder is BinHexDecoder) { _binDecoder.Reset(); } else { _binDecoder = new BinHexDecoder(); } } if (_nsIncReadOffset == _curNode.value.Length) { return(0); } _binDecoder.SetNextOutputBuffer(buffer, index, count); _nsIncReadOffset += _binDecoder.Decode(_curNode.value, _nsIncReadOffset, _curNode.value.Length - _nsIncReadOffset); return(_binDecoder.DecodedCount); } goto case XmlNodeType.Text; case XmlNodeType.Text: Debug.Assert(AttributeCount > 0); return(await reader.ReadContentAsBinHexAsync(buffer, index, count).ConfigureAwait(false)); default: Debug.Assert(false); return(0); } case State.Interactive: _state = State.ReadContentAsBinHex; goto case State.ReadContentAsBinHex; case State.ReadContentAsBinHex: int read = await reader.ReadContentAsBinHexAsync(buffer, index, count).ConfigureAwait(false); if (read == 0) { _state = State.Interactive; ProcessNamespaces(); } return(read); case State.ReadContentAsBase64: case State.ReadElementContentAsBase64: case State.ReadElementContentAsBinHex: throw new InvalidOperationException(ResXml.Xml_MixingBinaryContentMethods); default: Debug.Assert(false); return(0); } }