Exemplo n.º 1
0
        public async Task Decode(EbmlParser parser, bool force, bool recursive)
        {
            if (Decoded && !force)
            {
                return;
            }
            if (parser == null)
            {
                throw new ArgumentNullException(nameof(parser));
            }
            if (parser.DataAccessor == null)
            {
                throw new InvalidOperationException(
                          ExceptionsResourceManager.ResourceManager.GetString("InvalidDecodeState", CultureInfo.CurrentCulture));
            }

            if (DataPosition >= EndPosition)
            {
                Console.WriteLine($"Element {this} contains no children");
                return;
            }

            await _parserSemaphoreSlim.WaitAsync().ConfigureAwait(false);

            try
            {
                _parserPosition = DataPosition;
                while (_parserPosition < EndPosition)
                {
                    var element = await parser.ParseElementAt(_parserPosition, Parent).ConfigureAwait(false);

                    if (element == null)
                    {
                        _parserPosition = parser.DataAccessor.Position;
                        continue;
                    }
                    if (recursive)
                    {
                        await element.Decode(parser).ConfigureAwait(false);
                    }
                    _parserPosition = parser.DataAccessor.Position;
                    InsertElement(element);
                }

                Decoded = true;
            }
            finally
            {
                _parserSemaphoreSlim.Release(1);
            }
        }
Exemplo n.º 2
0
        public async Task <EbmlElement?> DecodeChildAt(EbmlParser parser, long index)
        {
            if (parser is null)
            {
                throw new ArgumentNullException(nameof(parser));
            }
            if (index < DataPosition || index >= EndPosition)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            var child = await parser.ParseElementAt(index).ConfigureAwait(false);

            if (child != null)
            {
                InsertElement(child);
            }
            return(child);
        }
Exemplo n.º 3
0
        public async Task <EbmlElement?> DecodeNextChild(EbmlParser parser)
        {
            if (parser is null)
            {
                throw new ArgumentNullException(nameof(parser));
            }

            var lastChild = _children.LastOrDefault().Value;

            if (lastChild.Position > EndPosition)
            {
                throw new EndOfMasterException(ExceptionsResourceManager.ResourceManager.GetString("NoChildLeft", CultureInfo.CurrentCulture));
            }

            var index = lastChild.EndPosition;
            var child = await parser.ParseElementAt(index).ConfigureAwait(false);

            if (child != null)
            {
                InsertElement(child);
            }
            return(child);
        }