/// <summary>
        /// 开始组装包。
        /// </summary>
        protected override void Packaging()
        {
            var topicBytes = Topic.ToBytes();//主题数据

            Data    = new byte[topicBytes.Length + BodyBytes.Length + (QoS > 0 ? 4 : 2)];
            Data[0] = (byte)(topicBytes.Length >> 8);
            Data[1] = (byte)(topicBytes.Length & 255);
            topicBytes.CopyTo(Data, 2);
            if (QoS > 0)
            {
                Data[topicBytes.Length + 2] = (byte)(Identifier >> 8);
                Data[topicBytes.Length + 3] = (byte)(Identifier & 255);
            }
            BodyBytes.CopyTo(Data, Data.Length - BodyBytes.Length);//复制消息内容
            topicBytes = null;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Reads the specified type (T) into Body
 /// </summary>
 // ReSharper disable once MemberCanBeProtected.Global
 public virtual void Read()
 {
     Body = BodyBytes.ReadStruct <T>();
 }