public void ToData(byte[] _data) { _data[0] = tag1; _data[1] = tag2; var d = BitConverter.GetBytes(msgid); _data[2] = d[0]; _data[3] = d[1]; for (var i = 4; i < 62; i++) { var seek = i - 4; if (seek < this.data.Length) { _data[i] = this.data[seek]; } else { _data[i] = 0; } } var crc = SignTool.ComputeCRC32(_data, 0, 62); _data[62] = crc[0]; _data[63] = crc[1]; }
public void FromData(byte[] _data) { this.tag1 = _data[0]; this.tag2 = _data[1]; this.msgid = BitConverter.ToUInt16(_data, 2); for (var i = 4; i < 62; i++) { this.data[i - 4] = _data[i]; } this.crc1 = _data[62]; this.crc2 = _data[63]; var crc = SignTool.ComputeCRC32(_data, 0, 62); if (this.crc1 != crc[0] || this.crc2 != crc[1]) { throw new Error_MsgHashNotMatch("the message hash not match"); } }