Lawo.EmberPlusSharp.Ember.EmberReader.Read C# (CSharp) Méthode

Read() public méthode

Advances the reader to the next data value in the stream.

After this method returns true, client code usually examines the values of the EmberReader.InnerNumber and OuterId properties to determine the next steps. This method returns true in the following situations: The identifiers and lengths of a data value with primitive encoding have been read successfully. Call the appropriate ReadContents method to retrieve the contents of the data value. The identifiers and lengths of a sequence, a set or an application-defined type have been read successfully. Call Read to advance the reader to the data values of the container. The reader has read past the end of a sequence, a set or an application-defined type with definite length. Call Read to advance the reader to the data values located after the container. The End-of-contents marker of a sequence, a set or an application-defined type with indefinite length has been read successfully. Call Read to advance the reader to the data values located after the container.

When a EmberReader is first created and initialized, there is no information available. You must call Read to read the first data value.

Possibly unread contents of the previous data value with primitive encoding is skipped automatically.

An error occurred while parsing the EmBER-encoded data, see /// for more information. has been called.
public Read ( ) : bool
Résultat bool
        public bool Read()
        {
            this.AssertNotDisposed();

            if (this.CanReadContents)
            {
                var endPosition = this.EndPosition.GetValueOrDefault();

                while ((this.readBuffer.Position < endPosition) &&
                    ((this.readBuffer.Index < this.readBuffer.Count) || this.readBuffer.Read()))
                {
                    this.readBuffer.Index +=
                        (int)Math.Min(this.readBuffer.Count - this.readBuffer.Index, endPosition - this.readBuffer.Position);
                }

                this.CanReadContents = false;
            }

            this.innerNumber = null;
            this.outer = null;

            if ((this.endPositions.Count > 0) && (this.readBuffer.Position > this.EndPosition))
            {
                throw CreateEmberException("Incorrect length at position {0}.", this.endPositions.Peek().LengthPosition);
            }

            while ((this.endPositions.Count > 0) && (this.readBuffer.Position == this.EndPosition))
            {
                var endPosition = this.endPositions.Pop();

                if (IsContainer(endPosition))
                {
                    this.innerNumber = Ember.InnerNumber.EndContainer;
                    return true;
                }
            }

            return this.ReadCore();
        }

Usage Example

Exemple #1
0
        private static void AssertDecode(int expectedInnerNumber, Action <EmberReader> assertEqual, params byte[] input)
        {
            using (var stream = new MemoryStream(input))
                using (var reader = new EmberReader(stream, 1))
                {
                    AssertThrow <InvalidOperationException>(() => reader.InnerNumber.GetHashCode().Ignore());
                    AssertThrow <InvalidOperationException>(() => reader.OuterId.Ignore());
                    AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject());
                    Assert.IsFalse(reader.CanReadContents);
                    Assert.IsTrue(reader.Read());
                    Assert.AreEqual(EmberId.CreateApplication(0), reader.OuterId);
                    Assert.AreEqual(expectedInnerNumber, reader.InnerNumber);
                    assertEqual(reader);
                    AssertThrow <InvalidOperationException>(() => reader.ReadContentsAsObject());
                    Assert.IsFalse(reader.Read());

                    reader.Dispose();
                    Assert.IsFalse(reader.CanReadContents);
                    AssertThrow <ObjectDisposedException>(() => reader.InnerNumber.Ignore());
                    AssertThrow <ObjectDisposedException>(() => reader.OuterId.Ignore());
                    AssertThrow <ObjectDisposedException>(() => reader.ReadContentsAsObject());
                }

            using (var writer = XmlWriter.Create(Console.Out, new XmlWriterSettings()
            {
                Indent = true
            }))
            {
                new EmberConverter(GlowTypes.Instance).ToXml(input, writer);
                Console.WriteLine();
                Console.WriteLine();
            }
        }
All Usage Examples Of Lawo.EmberPlusSharp.Ember.EmberReader::Read