using InABox.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InABox.Rpc
{
    public class RpcPush : ISerializeBinary
    {
        public Type Type { get; set; }

        public BaseObject Object { get; set; }

        public void SerializeBinary(CoreBinaryWriter writer)
        {
            writer.Write(Type.EntityName());
            writer.WriteObject(Object, Type);
        }

        public void DeserializeBinary(CoreBinaryReader reader)
        {
            Type = CoreUtils.GetEntity(reader.ReadString());
            Object = reader.ReadObject<BaseObject>(Type);
        }

        public static RpcPush Create<TPush>(TPush push)
            where TPush : BaseObject
        {
            return new RpcPush
            {
                Type = typeof(TPush),
                Object = push
            };
        }
    }
}
