using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper5.Ietf.Rfc2236
{
    internal class IgmpMessage
    {
        public IgmpMessage(byte[] buffer)
        {
            Type = (IgmpType)buffer[0];
            MaxResponseTime = new TimeSpan(0, 0, 0, 0, ((int)buffer[1]) * 100);
            Checksum = BitConverter.ToUInt16(buffer, 2);
            
            ReadOnlySpan<byte> rosb = new ReadOnlySpan<byte>(buffer, 4, 4);
            GroupAddress = new IPAddress(rosb);
        }

        public IPAddress GroupAddress { get; private set; }

        public ushort Checksum { get; private set; }

        public TimeSpan MaxResponseTime { get; private set; }

        public IgmpType Type { get; private set; }
    }
}
