public virtual bool Store(MemoryStream _buf_) { try { if (null != account_id) { int account_id_length = Encoding.UTF8.GetByteCount(account_id); _buf_.Write(BitConverter.GetBytes(account_id_length), 0, sizeof(int)); _buf_.Write(Encoding.UTF8.GetBytes(account_id), 0, account_id_length); } else { _buf_.Write(BitConverter.GetBytes(0), 0, sizeof(int)); } if (false == AccountType_Serializer.Store(_buf_, account_type)) { return(false); } if (null != user_name) { int user_name_length = Encoding.UTF8.GetByteCount(user_name); _buf_.Write(BitConverter.GetBytes(user_name_length), 0, sizeof(int)); _buf_.Write(Encoding.UTF8.GetBytes(user_name), 0, user_name_length); } else { _buf_.Write(BitConverter.GetBytes(0), 0, sizeof(int)); } } catch (System.Exception) { return(false); } return(true); }
public virtual bool Load(MemoryStream _buf_) { try { if (sizeof(int) > _buf_.Length - _buf_.Position) { return(false); } int account_id_length = BitConverter.ToInt32(_buf_.GetBuffer(), (int)_buf_.Position); _buf_.Position += sizeof(int); if (account_id_length > _buf_.Length - _buf_.Position) { return(false); } byte[] account_id_buf = new byte[account_id_length]; Array.Copy(_buf_.GetBuffer(), (int)_buf_.Position, account_id_buf, 0, account_id_length); account_id = System.Text.Encoding.UTF8.GetString(account_id_buf); _buf_.Position += account_id_length; if (false == AccountType_Serializer.Load(ref account_type, _buf_)) { return(false); } } catch (System.Exception) { return(false); } return(true); }
public virtual int Size() { int nSize = 0; try { nSize += sizeof(int); if (null != account_id) { nSize += Encoding.UTF8.GetByteCount(account_id); } nSize += AccountType_Serializer.Size(account_type); } catch (System.Exception) { return(-1); } return(nSize); }