public GenericValue ReadGeneric(byte tag = 255)
{
CopyingStream cstream = new CopyingStream(_stream);
BinaryReader creader = new BinaryReader(cstream);
Stream ostream = _stream;
BinaryReader oreader = _reader;
long end = 0;
int depth = 0;
ReadOpenTag(tag);
if (_hasHeader)
throw new Exception("Can't read generic tag when header is already cached");
try
{
_stream = cstream;
_reader = creader;
while (depth >= 0)
{
end = cstream.Position;
_peekHeader();
// TODO: EOF handling
if (_lvt == LVT.Type)
{
if (depth == 0 && _type == TagType.Close && _tagNumber == tag)
break;
else if (_type == TagType.Open)
depth++;
else if (_type == TagType.Close)
depth--;
}
else if (_lvt == LVT.Length)
{
cstream.Skip(_length);
}
_hasHeader = false;
}
}
finally
{
_stream = ostream;
_reader = oreader;
}
ReadCloseTag(tag);
return new TaggedGenericValue(cstream.MemoryStream.GetBuffer(), 0, (int)end);
}