コード例 #1
0
        private int ReadContentAsBinary(byte[] buffer, int index, int count)
        {
            Debug.Assert(_decoder != null);

            if (_isEnd)
            {
                Reset();
                return(0);
            }
            _decoder.SetNextOutputBuffer(buffer, index, count);

            for (; ;)
            {
                // use streaming ReadValueChunk if the reader supports it
                if (_canReadValueChunk)
                {
                    for (; ;)
                    {
                        if (_valueOffset < _valueChunkLength)
                        {
                            int decodedCharsCount = _decoder.Decode(_valueChunk, _valueOffset, _valueChunkLength - _valueOffset);
                            _valueOffset += decodedCharsCount;
                        }
                        if (_decoder.IsFull)
                        {
                            return(_decoder.DecodedCount);
                        }
                        Debug.Assert(_valueOffset == _valueChunkLength);
                        if ((_valueChunkLength = _reader.ReadValueChunk(_valueChunk, 0, ChunkSize)) == 0)
                        {
                            break;
                        }
                        _valueOffset = 0;
                    }
                }
                else
                {
                    // read what is reader.Value
                    string value             = _reader.Value;
                    int    decodedCharsCount = _decoder.Decode(value, _valueOffset, value.Length - _valueOffset);
                    _valueOffset += decodedCharsCount;

                    if (_decoder.IsFull)
                    {
                        return(_decoder.DecodedCount);
                    }
                }

                _valueOffset = 0;

                // move to next textual node in the element content; throw on sub elements
                if (!MoveToNextContentNode(true))
                {
                    _isEnd = true;
                    return(_decoder.DecodedCount);
                }
            }
        }
コード例 #2
0
 internal int CopyToBinary(IncrementalReadDecoder decoder, int valueOffset)
 {
     if (_value == null)
     {
         Debug.Assert(_valueStartPos != -1);
         Debug.Assert(_chars != null);
         return(decoder.Decode(_chars, _valueStartPos + valueOffset, _valueLength - valueOffset));
     }
     else
     {
         return(decoder.Decode(_value, valueOffset, _value.Length - valueOffset));
     }
 }