private void ReadSequence(EndianBinaryReader reader, SpecificCharacterSet encoding, long start) { Tag lookahead = null; // if we have somethign to read and we are not at the end of the stream if (length != 0 && position != stream.Length) { // look ahead and see if we can find an item delimiter tag lookahead = DataSet.PeekTag(reader, this.syntax); //System.Diagnostics.Debug.WriteLine(String.Format("0x{0:X8}:{0}: Peek {1} in ReadSequence", stream.Position, lookahead.Description)); // as long as we have item tags // TODO if we do not find an item tag that is a problem while (lookahead.Equals(t.Item)) { // position past the tag group and element stream.Position += sizeof(ushort) + sizeof(ushort); // find out the length of the item uint count = reader.ReadUInt32(); //System.Diagnostics.Debug.WriteLine(String.Format("0x{0:X8}:{0}: Reading item of length={1}", stream.Position, (count == UInt32.MaxValue) ? "undefined" : count.ToString())); Elements elements = new Elements(); items.Add(elements); long place = stream.Position; // call scan recursively, passing in the length limit which is the size of the // entire item along with the sequence key name long temp = (count != UInt32.MaxValue) ? (place + count) : -1; place = DataSet.Scan(this, stream, elements, place, temp, UInt16.MaxValue, syntax, encoding); //System.Diagnostics.Debug.WriteLine(String.Format("0x{0:X8}:{0}: Finished reading item", stream.Position)); if (stream.Position < stream.Length) { lookahead = DataSet.PeekTag(reader, this.syntax); //System.Diagnostics.Debug.WriteLine(String.Format("0x{0:X8}:{0}: Peek {1} in ReadSequence", stream.Position, lookahead.Name)); } // the next tag is either another item in the sequence, a sequence delimiter, or the next tag // after the sequence. we only get the next tag if we are not at the end of the file and // we have an undefined sequence length if (length == UInt32.MaxValue) { if (lookahead.Equals(t.SequenceDelimitationItem)) { //System.Diagnostics.Debug.WriteLine(String.Format("0x{0:X8}:{0}: undefined length, found {1}:{2}", stream.Position, lookahead.Description, lookahead.Name)); break; } } else { if (stream.Position >= start + length) { break; } if (!lookahead.Equals(t.Item)) { } } } if (length == UInt32.MaxValue) { if (lookahead.Equals(t.SequenceDelimitationItem)) { //System.Diagnostics.Debug.WriteLine(String.Format("0x{0:X8}:{0}: undefined length, found {1}:{2}", stream.Position, lookahead.Description, lookahead.Name)); // position stream beyond delimitation tag stream.Position += sizeof(ushort) * 2; // no need to check zero int zero = reader.ReadInt32(); } } } }