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

namespace skyscraper5.Dvb.DataBroadcasting.Biop
{
    public class ObjectLocation
    {
        public ObjectLocation(MemoryStream ms)
        {
            if (ms.ReadUInt32BE() != 0x49534f50)
                throw new DvbException("invalid magic!");

            byte componentDataLength = ms.ReadUInt8();

            CarouselId = ms.ReadUInt32BE();
            ModuleId = ms.ReadUInt16BE();

            byte version_major = ms.ReadUInt8();
            byte version_minor = ms.ReadUInt8();
            Version = new Version(version_major, version_minor);

            byte objectKeyLength = ms.ReadUInt8();
            ObjectKey = ms.ReadBytes(objectKeyLength);
        }

        public byte[] ObjectKey { get; private set; }

        public Version Version { get; private set; }

        public ushort ModuleId { get; private set; }

        public uint CarouselId { get; private set; }
    }
}
