using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper.IO;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.DsmCc.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x21,"PMT")]
    [BannedTable("TSDT")]
    class DeferredAssociationTagsDescriptor : TsDescriptor
    {
        public DeferredAssociationTagsDescriptor(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer, false);
            byte associationTagLoopLength = ms.ReadUInt8();
            if (associationTagLoopLength % 2 != 0)
                return;
            AssociationTag = new ushort[associationTagLoopLength / 2];
            for (int i = 0; i < associationTagLoopLength / 2; i++)
            {
                AssociationTag[i] = ms.ReadUInt16BE();
            }

            TransportStreamId = ms.ReadUInt16BE();
            ProgramNumber = ms.ReadUInt16BE();
        }

        public ushort ProgramNumber { get; private set; }

        public ushort TransportStreamId { get; private set; }

        public ushort[] AssociationTag { get; private set; }
    }
}
