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); } } }
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)); } }
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); } }
public override int ReadContentAsBase64(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("ReadContentAsBase64"); 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 Base64Decoder) { binDecoder.Reset(); } else { binDecoder = new Base64Decoder(); } } 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(reader.ReadContentAsBase64(buffer, index, count)); default: Debug.Assert(false); return(0); } case State.Interactive: state = State.ReadContentAsBase64; goto case State.ReadContentAsBase64; case State.ReadContentAsBase64: int read = reader.ReadContentAsBase64(buffer, index, count); if (read == 0) { state = State.Interactive; ProcessNamespaces(); } return(read); case State.ReadContentAsBinHex: case State.ReadElementContentAsBase64: case State.ReadElementContentAsBinHex: throw new InvalidOperationException(Res.GetString(Res.Xml_MixingBinaryContentMethods)); default: Debug.Assert(false); return(0); } }