Ejemplo n.º 1
0
 public bool Load(MemoryStream _buf_)
 {
     try {
         if (sizeof(int) > _buf_.Length - _buf_.Position)
         {
             return(false);
         }
         int item_id_length = BitConverter.ToInt32(_buf_.GetBuffer(), (int)_buf_.Position);
         _buf_.Position += sizeof(int);
         if (item_id_length > _buf_.Length - _buf_.Position)
         {
             return(false);
         }
         byte[] item_id_buf = new byte[item_id_length];
         Array.Copy(_buf_.GetBuffer(), (int)_buf_.Position, item_id_buf, 0, item_id_length);
         item_id         = System.Text.Encoding.UTF8.GetString(item_id_buf);
         _buf_.Position += item_id_length;
         if (false == ItemType_Serializer.Load(ref item_type, _buf_))
         {
             return(false);
         }
         if (sizeof(uint) > _buf_.Length - _buf_.Position)
         {
             return(false);
         }
         item_seq        = BitConverter.ToUInt32(_buf_.GetBuffer(), (int)_buf_.Position);
         _buf_.Position += sizeof(uint);
     } catch (System.Exception) {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
        public int Size()
        {
            int nSize = 0;

            try {
                nSize += sizeof(int);
                if (null != item_id)
                {
                    nSize += Encoding.UTF8.GetByteCount(item_id);
                }
                nSize += ItemType_Serializer.Size(item_type);
                nSize += sizeof(uint);
            } catch (System.Exception) {
                return(-1);
            }
            return(nSize);
        }
Ejemplo n.º 3
0
 public bool Store(MemoryStream _buf_)
 {
     try {
         if (null != item_id)
         {
             int item_id_length = Encoding.UTF8.GetByteCount(item_id);
             _buf_.Write(BitConverter.GetBytes(item_id_length), 0, sizeof(int));
             _buf_.Write(Encoding.UTF8.GetBytes(item_id), 0, item_id_length);
         }
         else
         {
             _buf_.Write(BitConverter.GetBytes(0), 0, sizeof(int));
         }
         if (false == ItemType_Serializer.Store(_buf_, item_type))
         {
             return(false);
         }
         _buf_.Write(BitConverter.GetBytes(item_seq), 0, sizeof(uint));
     } catch (System.Exception) {
         return(false);
     }
     return(true);
 }