PASSWORD_OBJ_INTERFACE.cs 1.81 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLY.Thick.Base.Common;

namespace FLY.Thick.Base.OBJ_INTERFACE
{
    public class PASSWORD_OBJ_INTERFACE
    {
潘栩锋's avatar
潘栩锋 committed
11

潘栩锋's avatar
潘栩锋 committed
12 13 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
        #region Pack
        public class Pack_List 
        {
            public List<PasswordCell> list;
            #region IPack 成员

            public byte[] ToBytes()
            {
                List<byte> buf = new List<byte>();
                
                buf.AddRange(BitConverter.GetBytes(list.Count()));
                for (int i = 0; i < list.Count();i++ )
                    buf.AddRange(list[i].ToBytes());
                return buf.ToArray();
            }

            public bool TryParse(byte[] value)
            {
                int count = 4;
                if (value.Length < count)
                    return false;
                int idx = 0;
                int len = BitConverter.ToInt32(value, idx);
                idx += 4;
                if (list == null)
                    list = new List<PasswordCell>();
                else
                    list.Clear();

                for (int i = 0; i < len; i++) 
                {
                    int cnt;
                    PasswordCell p = new PasswordCell();
                    if (!p.TryParse(value, idx, out cnt))
                        return false;
                    list.Add(p);
                    count += cnt;
                    idx += cnt;
                }
                return true;
            }

            #endregion
        }
        #endregion

        #region GetValue
        public const UInt16 GET_PWLIST = 1;
        #endregion
        #region SetValue
        public const UInt16 SET_PWLIST = 1;
        #endregion
        #region PushMsg
        public const UInt16 PUSH_PWLIST = 1;
        #endregion
    }
}