Exemplo n.º 1
0
 public static void BuildResp(IChannelHandlerContext context, Message message)
 {
     var respHbType      = Convert.ToInt32(HeartBeatType.KeepAlive);
     var coreRespContent = BytesUtil.Int32ToBytes(respHbType);
     var serial          = message.Bodies[0].SerialNumber;
     var content         = BuildContent(IdType.HeartBeat, MsgType.State, OpsType.ReportCommand, 0, serial, coreRespContent);
 }
Exemplo n.º 2
0
        public static byte[] BuildContent(IdType idType, MsgType msgType, OpsType opsType, int attr, int serial, byte[] core)
        {
            var coreLen = core == null ? 0 : core.Length;
            var buffer  = Unpooled.Buffer(coreLen + 20);

            var msgId      = Convert.ToInt32(idType);
            var msgIdBytes = BytesUtil.Int32ToBytes(msgId);

            buffer.WriteBytes(msgIdBytes);

            var timestamp = TimeUtil.GetTimeStamp();
            var timeBytes = BytesUtil.Int32ToBytes(timestamp);

            buffer.WriteBytes(timeBytes);

            var msgTypeCode  = Convert.ToInt16(msgType);
            var msgTypeBytes = BytesUtil.Int16ToBytes(msgTypeCode);

            buffer.WriteBytes(msgTypeBytes);

            var opsTypeCode  = Convert.ToInt16(opsType);
            var opsTypeBytes = BytesUtil.Int16ToBytes(opsTypeCode);

            buffer.WriteBytes(opsTypeBytes);

            var attrBytes = BytesUtil.Int16ToBytes((Int16)attr);

            buffer.WriteBytes(attrBytes);

            var length   = coreLen + 4;
            var lenBytes = BytesUtil.Int16ToBytes((Int16)length);

            buffer.WriteBytes(lenBytes);

            var serialBytes = BytesUtil.Int32ToBytes(serial);

            buffer.WriteBytes(serialBytes);

            if (core != null)
            {
                buffer.WriteBytes(core);
            }
            return(buffer.Array);
        }