using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;
using FLY.Thick.Base.Common;

namespace FLY.Thick.Base.OBJ_INTERFACE
{
    public class CURVE_OBJ_INTERFACE
    {

    
        #region Pack
        public class Pack_CurveList : IPack
        {
            public CurveCorrectWay correctway = CurveCorrectWay.OnePointIsScale;
            public CurveType flag = CurveType.E;
            public CurveCell[] list;

            #region IPack 成员

            public byte[] ToBytes()
            {
                List<byte> buf=new List<byte>();
                buf.AddRange(BitConverter.GetBytes((int)correctway));
                buf.AddRange(BitConverter.GetBytes((int)flag));

                buf.AddRange(BitConverter.GetBytes(list.Length));
                foreach(CurveCell c in list)
                {
                    buf.AddRange(BitConverter.GetBytes(c.Value));
                    buf.AddRange(BitConverter.GetBytes(c.AD));
                    buf.AddRange(BitConverter.GetBytes(c.RevisedAD));
                }
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                int cnt = 12;
                if (value.Length < cnt)
                    return false;
                int idx = 0;
                correctway = (CurveCorrectWay)BitConverter.ToInt32(value, idx);
                idx += 4;

                flag = (CurveType)BitConverter.ToInt32(value, idx);
                idx += 4;

                int len = BitConverter.ToInt32(value, idx);
                idx += 4;
                cnt += len * 12;
                if (value.Length < cnt)
                    return false;

                list = new Common.CurveCell[len];
                for (int i = 0; i < len; i++)
                {
                    list[i] = new Common.CurveCell();
                    list[i].Value = BitConverter.ToInt32(value, idx);
                    idx += 4;
                    list[i].AD = BitConverter.ToInt32(value, idx);
                    idx += 4;
                    list[i].RevisedAD = BitConverter.ToInt32(value, idx);
                    idx += 4;
                }
                return true;
            }

            #endregion
        }
       
        #endregion

        #region GetValue
        /// <summary>
        /// Pack_CurveList
        /// </summary>
        public const UInt16 GET_CURVELIST = 0;
        #endregion
        #region SetValue
        /// <summary>
        /// Pack_CurveList
        /// </summary>
        public const UInt16 SET_CURVELIST = 0; 
        #endregion
        #region PushMsg
        /// <summary>
        /// Pack_CurveList
        /// </summary>
        public const UInt16 PUSH_CURVELIST = 0; 
        #endregion
    }
}
