Buffer自我拷贝时,只设置长度,然后直接返回长度,代表已拷贝。

令牌配置和微网配置需要在Load之后重新设置扩展属性的长度,ByteArray需要保存之前把长度读取出来。
This commit is contained in:
nnhy 2016-03-17 11:39:20 +00:00
parent 2669740a71
commit 7c420049ad
6 changed files with 52 additions and 11 deletions

View File

@ -54,7 +54,8 @@ void TinyClient::Open()
Control->Address = Cfg->Address;
Server = Cfg->Server;
Password.Load(Cfg->Password, ArrayLength(Cfg->Password));
//Password.Load(Cfg->Password, ArrayLength(Cfg->Password));
Password = cfg->Pass;
}
HardCrc = Crc::Hash16(Buffer(Sys.ID, 16));
@ -356,9 +357,10 @@ bool TinyClient::OnJoin(const TinyMessage& msg)
Cfg->Address = dm.Address;
Control->Address = dm.Address;
//Password = dm.Password;
Password.Copy(0, dm.Password, 0, -1);
Password.Save(Cfg->Password, ArrayLength(Cfg->Password));
Password = dm.Password;
Cfg->Pass = dm.Password;
//Password.Copy(0, dm.Password, 0, -1);
//Password.Save(Cfg->Password, ArrayLength(Cfg->Password));
// 记住服务端地址
Server = dm.Server;

View File

@ -3,25 +3,43 @@
TinyConfig* TinyConfig::Current = nullptr;
TinyConfig::TinyConfig() : ConfigBase()
TinyConfig::TinyConfig() : ConfigBase(),
Pass(_Pass, sizeof(_Pass))
{
_Name = "TinyCfg";
_Start = &Length;
_End = &TagEnd;
Init();
}
void TinyConfig::Init()
{
ConfigBase::Init();
Length = Size();
Kind = Sys.Code;
PingTime = 20;
OfflineTime = 60;
Pass.SetLength(_PassLen);
}
void TinyConfig::Load()
{
ConfigBase::Load();
Pass.SetLength(_PassLen);
}
void TinyConfig::Save() const
{
auto cfg = (TinyConfig*)this;
cfg->_PassLen = Pass.Length();
ConfigBase::Save();
}
TinyConfig* TinyConfig::Create()

View File

@ -32,17 +32,23 @@ public:
byte HardVer; // 硬件版本
byte SoftVer; // 软件版本
byte Password[16]; // 通信密码
byte _PassLen; // 密码长度
byte _Pass[15]; // 通信密码
byte Mac[6]; // 无线物理地址
byte TagEnd; // 数据区结束标识符
ByteArray Pass;
TinyConfig();
virtual void Init();
virtual void Load();
virtual void Save() const;
static TinyConfig* Current;
static TinyConfig* Create();
private:
byte TagEnd; // 数据区结束标识符
};
//#pragma pack(pop) // 恢复对齐状态

View File

@ -32,6 +32,17 @@ void TokenConfig::Init()
Protocol = ProtocolType::Udp;
}
void TokenConfig::Load()
{
ConfigBase::Load();
User = _User;
Pass = _Pass;
VisitToken = _VisitToken;
Server = _Server;
Vendor = _Vendor;
}
void TokenConfig::Show() const
{
#if DEBUG

View File

@ -35,6 +35,7 @@ public:
TokenConfig();
virtual void Init();
virtual void Load();
virtual void Show() const;
String User;

View File

@ -168,6 +168,9 @@ int Buffer::Copy(int destIndex, const void* src, int len)
// 放到这里判断,前面有可能自动扩容
if(!_Arr) return 0;
// 自我拷贝,跳过
if(_Arr == src) return len;
// 拷贝数据
if(len) memcpy((byte*)_Arr + destIndex, src, len);
@ -470,14 +473,14 @@ bool Array::SetLength(int len, bool bak)
/*void Array::SetBuffer(void* ptr, int len)
{
Release();
Buffer::SetBuffer(ptr, len);
}
void Array::SetBuffer(const void* ptr, int len)
{
SetBuffer((void*)ptr, len);
_canWrite = false;
}*/