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
{
    class Name
    {
        public Name(MemoryStream ms)
        {
            byte nameComponentsCount = ms.ReadUInt8();
            NameComponents = new Dictionary<string, string>();
            for (byte i = 0; i < nameComponentsCount; i++)
            {
                byte idLength = ms.ReadUInt8();
                string id = Encoding.UTF8.GetString(ms.ReadBytes(idLength));
                id = id.TrimEnd((char)0);
                byte kindLength = ms.ReadUInt8();
                string kind = Encoding.UTF8.GetString(ms.ReadBytes(kindLength));
                kind = kind.TrimEnd((char)0);
                NameComponents.Add(id, kind);
            }
        }

        public Dictionary<string,string> NameComponents { get; private set; }
    }
}
