Exemplo n.º 1
0
 public bool Store(MemoryStream _buf_)
 {
     try {
         if (null != user_id)
         {
             int user_id_length = Encoding.UTF8.GetByteCount(user_id);
             _buf_.Write(BitConverter.GetBytes(user_id_length), 0, sizeof(int));
             _buf_.Write(Encoding.UTF8.GetBytes(user_id), 0, user_id_length);
         }
         else
         {
             _buf_.Write(BitConverter.GetBytes(0), 0, sizeof(int));
         }
         _buf_.Write(BitConverter.GetBytes(user_seq), 0, sizeof(uint));
         _buf_.Write(BitConverter.GetBytes(items.Count), 0, sizeof(int));
         foreach (var items_itr in items)
         {
             ItemData items_elmt = items_itr;
             if (false == ItemData_Serializer.Store(_buf_, items_elmt))
             {
                 return(false);
             }
         }
     } catch (System.Exception) {
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
 public bool Load(MemoryStream _buf_)
 {
     try {
         if (sizeof(int) > _buf_.Length - _buf_.Position)
         {
             return(false);
         }
         int user_id_length = BitConverter.ToInt32(_buf_.GetBuffer(), (int)_buf_.Position);
         _buf_.Position += sizeof(int);
         if (user_id_length > _buf_.Length - _buf_.Position)
         {
             return(false);
         }
         byte[] user_id_buf = new byte[user_id_length];
         Array.Copy(_buf_.GetBuffer(), (int)_buf_.Position, user_id_buf, 0, user_id_length);
         user_id         = System.Text.Encoding.UTF8.GetString(user_id_buf);
         _buf_.Position += user_id_length;
         if (sizeof(uint) > _buf_.Length - _buf_.Position)
         {
             return(false);
         }
         user_seq        = BitConverter.ToUInt32(_buf_.GetBuffer(), (int)_buf_.Position);
         _buf_.Position += sizeof(uint);
         if (sizeof(int) > _buf_.Length - _buf_.Position)
         {
             return(false);
         }
         int items_length = BitConverter.ToInt32(_buf_.GetBuffer(), (int)_buf_.Position);
         _buf_.Position += sizeof(int);
         for (int items_itr = 0; items_itr < items_length; items_itr++)
         {
             ItemData items_val = new ItemData();
             if (false == ItemData_Serializer.Load(ref items_val, _buf_))
             {
                 return(false);
             }
             items.Add(items_val);
         }
     } catch (System.Exception) {
         return(false);
     }
     return(true);
 }
Exemplo n.º 3
0
        public int Size()
        {
            int nSize = 0;

            try {
                nSize += sizeof(int);
                if (null != user_id)
                {
                    nSize += Encoding.UTF8.GetByteCount(user_id);
                }
                nSize += sizeof(uint);
                nSize += sizeof(int);
                foreach (var items_itr in items)
                {
                    ItemData items_elmt = items_itr;
                    nSize += ItemData_Serializer.Size(items_elmt);
                }
            } catch (System.Exception) {
                return(-1);
            }
            return(nSize);
        }