CURVE_OBJ_INTERFACE.cs 2.75 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11
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
    {
潘栩锋's avatar
潘栩锋 committed
12 13

    
潘栩锋's avatar
潘栩锋 committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
        #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
    }
}